In OWASP XSS cheat sheet it is written
In addition to the 5 characters significant in XML (&, <, >, ", '), the forward slash is included as it helps to end an HTML entity.
So the recommended escapings are
& --> &
< --> <
> --> >
" --> "
' --> '
/ --> /
What if I skipped escapings of /
? What are the examples of attacker payload using just /
that can trigger XSS or other attack (assuming & < > " '
are all escaped)?
In my particular scenario, we have an XSS filter in the Java servlet, which sanitizes the payload of all incoming HTTP requests (it can be argued if it's a good solution or not), and it replaces / --> /
which is a pain because /
is a valid character in street names etc. One option would be to redecode / --> /
but I'm wondering if there are any merits of keeping /
escaped?
Edit: why I don't want to have /
to be escaped:
The /
is escaped before data comes to the Java code which saves stuff to DB. So, Java asks the DB to save escaped data, then when the frontend app asks Java to give us back the data, it gives back a JSON like
{something: "a / b"}
instead of
{something: "a / b"}
(well, to fix that, we could just have Java code iterate over the structure it returns and unescape it, but maybe there's no point in escaping it in the first place?)
Note that the same backend is consumed by many frontends, some of them non-HTML. It doesn't make any sense to serve escaped HTML data as a JSON, particularly for non-HTML consumers (correct me if I'm wrong).
Moreover, in HTML app, we use Angular code like this
<p>Hello {{name}}!</p>
which, when given a / b
, will print that string literally to the user (i.e. Angular does another round of escaping by replacing &
to &
etc.).
To have HTML entities interpreted, I'd have to use ng-bind-html
(see this plunk)
<p>Hello <span ng-bind-html="name"></span>!</p>
but I expect my JSON contents to be regular text, so I don't want to use ng-bind-html
as it lowers the security.
magic_quotes_gpc
back.