Attribute XSS Lab: Break Out of a Value When Angle Brackets Are Escaped

✨ AI Summary
ProfileMe drops your name into the value attribute of an input field, and it escapes angle brackets, so the usual tag-based payloads do nothing. But inside an attribute the dangerous character is the quote that closes the value — and that one is not escaped.
Lab at a glance: Intermediate · 70 XP · about 15 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Context decides which characters are dangerous. Reflected inside an HTML attribute value, your input does not need angle brackets to be exploitable — it needs the quote that ends the attribute. Escaping only < and > leaves the attribute context wide open.

The lesson: output encoding must match the context. Angle-bracket escaping is for HTML body context; attribute context needs the quote (and more) encoded too.

How ProfileMe reflects your name

Your ?name= value is placed inside value="…" on an input. Angle brackets are escaped, so you cannot open a new tag. But the double quote that closes the value is reflected as-is, so you can end the attribute and add your own — including an event handler.

The attack approach

  • Confirm your name is reflected inside an attribute value and that angle brackets are escaped.
  • Realise the quote that closes the attribute is the character that matters here.
  • Break out of the value with a quote, then add an event-handler attribute.
  • Have that handler call the lab's solve function.

Full walkthrough (spoiler)

If tag-based payloads keep failing, stop trying to open a tag and break the attribute instead — open the steps.

Show the step-by-step solution
  1. In the name parameter, start by closing the value attribute with a double quote.
  2. Add an event-handler attribute (such as an autofocus field with an onfocus handler) so no new tag is needed.
  3. Point the handler at window.seLabSolve('SE_LAB_XSS_ATTR_2026').
  4. Load the URL; your input breaks out of the value, the handler runs, and the lab marks you solved.

Why it works

The filter defended the wrong context. It escaped the characters that matter in HTML body text, but your input lands in an attribute, where the closing quote is the boundary. Leave that quote unescaped and the attacker simply ends the value and writes new attributes.

Core principleEncode output for its exact context. In an attribute value that means HTML-attribute-encoding the quote (and ampersand), not just angle brackets.

Where this happens in the real world

Context-mismatch XSS — defending body context while reflecting into an attribute, URL or script context — is a common cause of 'filtered but still vulnerable' findings. XSS sits under Injection (A03) in the OWASP Top 10 (2021), and context-aware output encoding is the standard fix.

How to defend against it

  • Use context-aware output encoding — attribute-encode in attribute context, including quotes and ampersands.
  • Always quote attribute values and rely on a templating engine that auto-encodes per context.
  • Prefer frameworks that escape by default rather than hand-rolled filters.
  • Add a Content-Security-Policy as a backstop against injected handlers.
Mr Elite tip: When a payload is 'filtered' but your input still reflects, check the context. Angle brackets escaped but quotes intact means an attribute breakout, not a tag injection.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is attribute-context XSS?
Cross-site scripting where input is reflected inside an HTML attribute value; the attacker breaks out using the closing quote and adds an event handler, with no angle brackets needed.
Why doesn't escaping angle brackets stop it?
Because in attribute context the dangerous character is the quote that ends the value, not the angle bracket. Body-context escaping defends the wrong boundary.
How do I fix it?
Use context-aware output encoding — attribute-encode quotes and ampersands in attribute context — quote all attributes, and prefer frameworks that auto-escape per context.
Which OWASP category?
Injection (A03) in the OWASP Top 10 (2021); XSS is part of that category.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *