Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text input doesn't make string HTML safe (can inject code to run on user's browser) #434

Open
lemniscate8 opened this issue Jun 30, 2021 · 1 comment

Comments

@lemniscate8
Copy link
Collaborator

lemniscate8 commented Jun 30, 2021

The Bug
Text inputs do not make value HTML safe when using .Value. Since there are places where URL parameters are used to populate an input field via .Value (see ConfigPanel.hpp) this is an entry point for arbitrary code execution in the user's browser.

To Reproduce
Here's some code:

#include "emp/web/web.hpp"
#include "emp/web/Input.hpp"

emp::web::Document doc("emp_base");


int main() {
  emp::web::Input in([]() { ; }, "text", "Label");
  in.Value("hi there\"/> <script> alert(\"hi there\"); </script> <input style='display: none'");
  doc << in;
}

Expected behavior
All the text set via Value should appear in the input. However, text after the quote character does not exist though programmatically accessing the value will give the full string.

Toolchain

  • OS: Mac
  • Compiler: Emscripten 1.38.48
  • Browser: Chrome
  • Empirical version: master

Possible Fix
We probably need to replace " with &quot; and in general make the string HTML safe.

@lemniscate8 lemniscate8 changed the title Input doesn't render text after " any quote character in string Text input doesn't render text after any quote " character in string Jun 30, 2021
@mercere99
Copy link
Member

I wonder if emp::to_literal() from string_utils.hpp needs to be run on the string to deal with special characters?

@lemniscate8 lemniscate8 changed the title Text input doesn't render text after any quote " character in string Text input doesn't make string HTML safe (can inject code to run on user's browser) Jul 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants