-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
When returning an HTML error, make sure it's safe #1763
Conversation
the returned error renders the HTML back to the user, causing a potential XSS issue. For example: http://example.com/api/endpoint?format=%3Cscript%3Ealert(document.cookie)%3C/script%3E Renders as html: The requested format '<script>alert(document.cookie)</script>' is not supported. When an error generates html back to the user, make sure it's properly escaped. Fixes issue #1762
I had to fix six specs to be "compliant", which really surprised me. The ones that return json in particular seem like maybe they're not setting their content-type appropriately to json and as such are returning a json blob in html code. Is this ok/correct? |
The ones that expect JSON should indeed set the correct content type, thanks for taking care of it. Looks like Rails 3 may be a problem. If it gets complicated we can discuss dropping support. |
Better, but not 🍏 :( |
@dblock ok specs passing now |
👋 I am a member of the GitHub team that sends security alerts. This issue was assigned CVE-2018-3769 which is now disclosed publicly therefore therefore we would like to send security alerts for it. However, in our curation process it was noticed that the latest version of Thank you for any information! 🙇 |
I've released 1.1.0. |
I wonder why JSON error responses get escaped as well, and even specs are aligned to do that. That breaks existing JSON apis, since json doesn't understand " instead of " I have such code: content_type :json, 'application/json'
default_format :json
rescue_from Grape::Knock::ForbiddenError do
error!({ error: :unauthenticated }, 401)
end and it returns |
@Kukunin Reopen a bug, maybe with a fix, AFAIK that looks like a bug to me assuming the content type returned is |
When calling into an API specifying a crafted format that is HTML,
the returned error renders the HTML back to the user, causing a potential XSS
issue. For example:
http://example.com/api/endpoint?format=%3Cscript%3Ealert(document.cookie)%3C/script%3E
Renders as html:
The requested format '<script>alert(document.cookie)</script>' is not supported.
When an error generates html back to the user, make sure it's properly escaped.
Fixes issue #1762