Skip to content

js escaper fails to escape </script> #114

@arnaud-lb

Description

@arnaud-lb

A closing script tag, even placed inside quotes, even inside <![CDATA section, will close a <script> tag:

<script type="text/javascript">
var = "</script>"; // this closes the script tag
</script>

The js escaper should be able to catch this.

Looking at how others do to escape this sort of things, I found multiple solutions :

  • Change </script> into '</sc' + 'ript>' : not suitable for a generic escaper (i.e. depends on single or double quotes)
  • Escape '/'. Changing </script> into <\/script> seems to successfully avoid the problem. I read that json encoders escape the '/' for this reason, but I'm unsure.
  • Use a white list of safe chars and escape everything others to \xHEX and \uUNICODE representation. This is totally safe, this can even escape html special chars and make escape('js') safe for html too (useful when doing things like onclick="fun({{somevar}})"). However this depends on the encoding (the escaper should be encoding aware anyway).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions