-
Notifications
You must be signed in to change notification settings - Fork 21
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
xss injection #20
Comments
Hi, thanks for the feedback. After thinking about this for a sec, you are likely correct, since the json-encoded data is put into an HTML comment block, which could be ended by malicious stuff in the data. However I don't agree with the js counterpart's approach; brute force replacing all Happy to think through solutions here if you want to provide a test case. |
The client-side decoder expects server-rendered JSON to be encoded. The client first reverses the conversion and only then parses to JSON. The server should mirror the decoder. Example: str_replace(['&', '>'], ['&', '>'], json_encode(data)); Unfortunately, there's no flag available to make $data = ['xss' => 'comment--><script>window.close()</script>'];
sprintf('<script type="application/json"><!--%s--></script>', json_encode($data));
// <script type="application/json"><!--{"xss":"comment--><script>window.close()</script>"}--></script>
sprintf('<script type="application/json"><!--%s--></script>', hypernova_encode($data));
// <script type="application/json"><!--{"xss":"comment--><script->window.close()</script->"}--></script> |
Hi,
The
getFallbackHTML
method does not escape the json for html here. It should escape the json before sprintf-ing it into html tags just like its js counterpart here.I'd be happy to contribute if PRs are welcome.
The text was updated successfully, but these errors were encountered: