In-depth lesson · XSS
Typical fixes
Every point the XSS reports back under this heading, best-backed first, each with the reports it is seen in.
-
Send a restrictive Content-Security-Policy that does not allow data: scripts.
-
Serve uploaded PDFs with a download disposition or from a separate origin so embedded JavaScript cannot run in the site origin.
-
Set text content instead of using innerHTML or jQuery.append with untrusted values.
-
Set the correct JSON content type and add the nosniff header so responses cannot be sniffed as HTML.
Seen in 2 reports
-
Strip active content from uploaded PDFs and SVGs and serve them with a download disposition.
-
Update the sanitiser to handle CDATA sections and data-* attributes.
-
Use textContent instead of innerHTML when inserting user-controlled text such as filenames.
-
Validate allowed characters in name fields and encode them in email templates.
-
Validate and encode parameters in drilldown components.
-
Validate that redirect targets are safe relative paths before assigning to a navigation sink.
-
Validate the forwarded-proto header as a simple protocol string and do not skip the whitelist based on the path prefix.
-
Validate the origin of incoming messages and avoid wildcard targetOrigin when sending them.
-
Account for browser-specific parsing quirks such as namespace switching, animation attributes, XSLT and Safari's image import behaviour in SVG sanitisers.
Seen in 1 report
-
Account for control characters when filtering javascript: URIs.
Seen in 1 report
-
Add a CSRF token check to the save endpoint and HTML-encode stored action names on output.
-
Add a CSRF token to the saving form and mark session cookies HttpOnly.
Seen in 1 report
-
Add authorisation checks and output encoding to the AJAX endpoint.
Seen in 1 report
-
Add CSRF protection to profile update endpoints so self-XSS cannot be forced onto victims.
Seen in 1 report
-
Add input validation and output encoding for the page size parameter.
Seen in 1 report
-
Add origin checks to the cookie-setting endpoint and encode cookie values reflected into the page.
Seen in 1 report
-
Add rel=noopener to links opened in a new tab and complete the URI scheme allow-list.
-
Add the sandbox attribute to rendered iframes to block script execution and top-level navigation.
Seen in 1 report
-
Anchor the hostname check and reject protocol-relative URLs.
Seen in 1 report
-
Apply HTML-specific escaping to all branding fields rather than checking one parameter against a blocklist.
Seen in 1 report
-
Apply htmlspecialchars to comment text before echoing it.
Seen in 1 report
-
Apply output encoding to name fields and enforce authorisation checks on profile lookups.
-
Apply output encoding to the display name on every page that renders it, not only on the profile page.
Seen in 1 report
-
Apply output encoding to XML responses and add CSRF protections to the POST endpoint.
Seen in 1 report
-
Apply the fragment-only URL check to namespaced attributes as well.
Seen in 1 report
-
Apply the same filename sanitisation to FTP uploads as to manual rename.
-
Apply the same HTML escaping to the new byline placeholder as to the credits placeholder.
Seen in 1 report
-
Apply the same sanitisation to dialog titles as elsewhere.
-
Apply the session check to GET requests as well as POST.
Seen in 1 report
-
Attempted attacks against the Flash file were redirected to a 404 page.
Seen in 1 report
-
Authenticate messages to the element picker and sanitise option fields.
Seen in 1 report
-
Automatically fetch newly released fixed library versions.
Seen in 1 report
-
Avoid building HTML strings from unescaped values and assigning them to innerHTML in privileged pages.
Seen in 1 report
-
Avoid innerHTML for search input and use text insertion instead.
Seen in 1 report
-
Avoid mark_safe with string formatting on user input and rely on Django's automatic escaping.
Seen in 1 report
-
Bind CAPTCHA tokens to the user's session and encode reflected input.
Seen in 1 report
-
Bind CSRF tokens to the user session.
Seen in 1 report
-
Bind login tokens to the original session.
Seen in 1 report
-
Block javascript: URLs entered in the address bar or received via redirects.
Seen in 1 report
-
Block javascript: URLs used as the target of HTTP redirects.
Seen in 1 report
-
Build absolute links from a configured canonical URL rather than the request Host header.
Seen in 1 report
-
Check authorisation on every nested identifier, not just the top-level one.
Seen in 1 report
-
Check file extension, MIME type and content server-side before storing and serving uploaded files.
Seen in 1 report
-
Check that redirect targets are safe http(s) URLs.
Seen in 1 report
-
Check that URLs from the search backend use http or https before creating an omnibox match.
Seen in 1 report
-
Check the context before replacing the current document in the XSLT error handler.
Seen in 1 report