5

Example:

<!DOCTYPE>
<html lang="en">
    <head>
        <title>XSS test</title>
        <style>
        div {
            background-color:red;
            height:100px;
            width:100px;
        }
        </style>
    </head>
    <body>
        <div></div>
    </body>
</html>

Would it be possible to inject JavaScript code using inside style tag? I have heard that it's possible to trigger XSS attacks through CSS.

Elon Than
  • 9,603
  • 4
  • 27
  • 37
Soarabh
  • 2,910
  • 9
  • 39
  • 57

1 Answers1

4

Yes, JavaScript can be executed even through CSS thanks to URL support in the latter. In general, you can execute JavaScript through any mechanism that allows you to specify URLs because of the javascript: and data: pseudo-URLs. As result there are numerous cross-site scripting vectors that work through CSS. For example:

<style>p[foo=bar{}*{-o-link:'javascript:alert(1)'}{}*{-o-link-source:current}*{background:red}]{background:green};</style>

More of them can be found on Mario Heiderich site http://heideri.ch/jso/#css

kravietz
  • 10,667
  • 2
  • 35
  • 27