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

Escape attributes by default #9

Merged
merged 11 commits into from
Nov 26, 2023
Merged

Escape attributes by default #9

merged 11 commits into from
Nov 26, 2023

Conversation

keithasaurus
Copy link
Owner

closes #7

  • escape by default on attributes
  • allow SafeString to override
  • tests to verify escaping/overriding
  • implement performance mitigation / optimization to avoid needing to escape for many (most?) attribute names
  • updated docs
  • remove mypyc github action step (compilation was failing because of these changes, but it's not being used anyway)

Thanks to @gcollazo for putting forth a good argument to doing this.

@gcollazo
Copy link

gcollazo commented Nov 26, 2023

I would remove all of the on* event attributes from the safe list as they are all exploitable if unsanitized user input is used.

Reference: https://portswigger.net/web-security/cross-site-scripting/cheat-sheet

@gcollazo
Copy link

gcollazo commented Nov 26, 2023

To better manage performance, consider having a default mode where everything is escaped (safe/slow) where one can opt out by using SafeString and a mode where nothing is escaped (unsafe/fast) where the user is responsible for escaping user input.

That will delegate the trade off decision to package consumers.

Reference: https://jinja.palletsprojects.com/en/3.1.x/templates/#html-escaping

@keithasaurus
Copy link
Owner Author

I would remove all of the on* event attributes from the safe list as they are all exploitable if unsanitized user input is used.

Perhaps the code is easy to misunderstand here. The only use of the safe keys lookup is for avoiding the escaping logic on the keys-only; and only if the keys exactly match. The result of escaping on those keys would produce no change, so it's ok to avoid if we know we can (and because a dict lookup is typically much faster than escaping in this case, it makes performance sense). The values are still be escaped.

@keithasaurus keithasaurus merged commit 131f2e2 into main Nov 26, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider escapeing argument keys and values to prevent XSS in some scenarios
2 participants