by onion2k · 10y ago · 0 comments
For example, if browsers flatly refused to load code from an external URL unless the address was whitelisted in the page's HTTP response headers then you'd make level 6's exploit impossible without much of an impact on web development.
The CORS header Access-Control-Allow-Origin can be used to force a browser to work that way, but only if a site sets it. I'm suggesting we're at the point now where browsers should be secure by default, even if it breaks some old sites.
# Disable the reflected XSS filter for demonstration purposes
self.response.headers.add_header("X-XSS-Protection", "0")
Example: ?a=<script>void('&b=');alert('XSS')</script>
The value of a is <script>void(' and the value of b is ');alert('XSS')</script>.
Exactly. I made a library for that:
https://www.npmjs.com/package/csp-by-api
Eg if your web app uses embedded Tweets, MixPanel, and GoogleFonts:
var policy = cspByAPI(basePolicy, ['twitter', 'mixpanel', 'googleFonts' ]);
Ie, the package maintains an up to date list of the image, script, etc sources for all those different embeds, so you only have to specify what your own code needs (that's the basePolicy).It's for node, but you can easily port it to Elixir or Python or Ruby.
Policies for 16 common CSP embeds are included, please send a pull request to add more.
That's the point I'm questioning - I think browsers should block by default and only allow things that are specifically allowed by the CSP (or by CORS).
I don't personally agree with the decisions - but I can understand why they are made. It's easier to say I'd personally choose to give devs the finger and tell them to fix their code than to actually give devs the finger and tell them to fix/update their code.
That wouldn't just break some old sites that would break most of them. Most sites use some type of tracking script, jquery or other shared library.
Some are. But in general, XSS (especially reflected) are not possible to block exclusively at the browser level.
> For example, if browsers flatly refused to load code from an external URL unless the address was whitelisted in the page's HTTP response headers then you'd make level 6's exploit impossible without much of an impact on web development.
See fastest963's comment.
Its pretty normal to include external scripts on a website (CDN for dependencies, tracking like google analytics etc)