-
Notifications
You must be signed in to change notification settings - Fork 2k
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
security: js injection #2974
Comments
@goto-bus-stop @mifi @aduh95 is this still relevant? |
For reference, we're now passing
However, the patch has not been released to a stable release yet: |
But do we still want to implement one of @mifi's suggestions, or will this suffice? AFAIK we're good currently.
|
Yes I believe those are the only safe options. A third safe option is to use a library like serialize-javascript to safely json stringify and escape html and js line terminators. See https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#rule-3-javascript-encode-before-inserting-untrusted-data-into-javascript-data-values To clarify: just doing normal escapehtml + normal json.stringify is not safe inside a <script> tag. |
Alright! At first, option 2 seems the most straightforward to me, if the token is indeed alphanumeric. |
I'm unconvinced that's true, |
https://github.com/zertosh/htmlescape does json.stringify+escaping |
Normal
Browser security is hard so imo it's best to just follow advice from experts. It's easy to make a mistake and leave a hole open if we try to make our own solution. Seems like https://github.com/zertosh/htmlescape handles the line terminators, but it does not seem to escape |
For the record, those line terminators should no longer be an issue in modern JS engines: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Globalaa_Objects/JSON/stringify#issue_with_plain_json.stringify_for_use_as_javascript
This change was apparently made in ES2019 (I thought it was older than that), so it's indeed probably fair to assume not everyone has updated their parser to support these.
+1 |
Does this mean we still want to go with option 2? IMO it's a simple change if it takes away any doubt. |
I also thnik 2 is the simplest. The only disadvantages are:
|
I created a PR with the |
See discussion in https://github.com/transloadit/uppy/pull/2967/files/f70ac754ba2074af8c5d3cad14568148d0fb1122#r659685817
uppy/packages/@uppy/companion/src/server/controllers/send-token.js
Line 55 in f4e99fa
The text was updated successfully, but these errors were encountered: