Skip to content
CSRF Write-up Intermediate

CSRF Bypass using cross frame scripting

The send-message form had a CSRF token, but when the token was removed the server returned the form with a new valid token and pre-filled values. By chaining this with cross-frame scripting (clickjacking), an attacker could make a victim submit a message without their knowledge.

Mr.Hacker Follow

Published on medium.com

So directly cutting to the point, there is a module in the web application to send messages to users as shown below.

?Mr.Hacker, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

The target was a public program on HackerOne. The report does not name the program or the application. The feature involved is a module that lets a user send messages to other users. The researcher, Mr.Hacker (@mr_hacker0007), describes the module as a form with a "Post Message" action, and the write-up opens with a screenshot of that form.

Send Message Form From the original on medium.com

Send Message Form

The goal was to send a message on behalf of a logged-in victim, that is, to perform a cross-site request forgery against the send-message action.

Setup

The write-up does not describe accounts, roles, versions or a test environment. The only tool named is Burp, used to generate the CSRF proof of concept. The attack depends on the application being vulnerable to cross frame scripting, which the report says affected the entire web application.

Finding it

The researcher first tested the send-message module for CSRF directly. That path was closed: the POST request carried a token which the server validated, so a forged request without a valid token was rejected.

The interesting behaviour appeared when the CSRF PoC generated in Burp was executed with the CSRF token removed. Instead of an error, the server responded with the same form values and a new CSRF token set in the new message form, returned as the response body. In other words, the server handed back a freshly rendered form, pre-filled with the submitted values and carrying a valid token.

That changes the picture. If the victim then clicks "Post Message" on that returned form, the request goes to the server with the form values already set by the server and with the valid token, and the request is executed successfully. The missing piece was getting the victim to make that click on the attacker's terms, and the researcher found it: the entire web application was vulnerable to cross frame scripting.

Exploitation

The attack chains two issues: the CSRF PoC that gets a valid token back from the server, and cross frame scripting, which lets the attacker load and interact with the application's pages inside an attacker page.

Step 1: build the CSRF PoC without the token

Generate a CSRF PoC in Burp for the send-message request, fill in the form values, and remove the CSRF token. The report does not reproduce the request or the PoC markup.

Step 2: observe the server's response

When the PoC is executed, the server responds with all form values pre-set in the response and also with a valid token. The response is a new message form, ready to submit.

Step 3: embed the CSRF file inside the clickjacking file

Because the application is vulnerable to cross frame scripting, the attacker includes the CSRF file inside the clickjacking file. The clickjacking page loads the CSRF file, which auto-submits the form with the chosen values.

CSRF File In Clickjacking From the original on medium.com

CSRF File In Clickjacking

Step 4: the server returns a token-bearing form

The server answers the auto-submitted request with the same form values set and a valid CSRF token, as in step 2.

Step 5: get the victim's click

The victim opens the malicious URL sent by the attacker. The clickjacking file loads the CSRF file, which auto-submits the form, and the response, the pre-filled form with a valid token, is loaded inside the clickjacking frame. When the victim clicks "Post Message", a valid request is generated and executed successfully.

Chaining CrossFrameScripting and CSRF From the original on medium.com

Chaining CrossFrameScripting and CSRF

The researcher's own summary of the scenario:

  1. The attacker will generate a valid csrf poc with burp with form values and removing csrf token.
  2. Now if we execute the csrf poc server will respond with all form values pre set in the response and also with a valid token, Hence an attacker will include the csrf file inside clickjacking file.
  3. So when the victim clicks on the malicious url sent by attacker, the clickjacking file will load the csrf file and inturn it would auto submit the form with the respective values and later server will send a response with the same form values set and also with the valid csrf token. Hence now the response is loaded using clickjacking and when the user clicks on Post Message it would generate a valid request and it will be executed successfully.

A video PoC is linked in the report: https://www.youtube.com/watch?v=cjp0ZcgscPA

Or watch on YouTube
From the original on medium.com

Root cause

The send-message request carried a token which the server validated, so a direct CSRF attempt was not possible. When the CSRF PoC was executed with the token removed, the server responded with the same form values and a new valid token in the new message form. That turns the token from a barrier into something the attacker can obtain through the victim's own browser, because the response is delivered to a page the attacker controls through framing.

The second half of the chain is the absence of frame protection. The report states that the entire web application was vulnerable to cross frame scripting, which is what allows the attacker's page to load the application, let the form auto-submit, and then place the returned form under the victim's cursor.

Impact

An attacker could send a message as a logged-in victim, provided the victim visits the malicious URL and clicks "Post Message". The researcher submitted the vulnerability and received a bounty reward.

The broader point the author makes is about chaining: cross frame scripting on its own is often treated as low impact and skipped as out of scope, but combined with the token-reflecting form behaviour it produced a working CSRF bypass. In the author's words, no vulnerability is low if we try to chain it with a few others, and low hanging fruits can give a great impact when used in a unique way.

Fix

Based on the behaviour described, the token check should reject a request with a missing or invalid token outright, without re-rendering the form with the submitted values and a new token. Separately, the application should not be frameable by third-party origins, for example through frame-ancestors or X-Frame-Options, which removes the cross frame scripting half of the chain.

Variants to test

  1. Token-reflecting error pages. Submit a state-changing form without its token and inspect the response. A positive result is a response body that contains the submitted values plus a fresh valid token, which can then be re-submitted.
  2. Framing on any authenticated page. Check whether the application can be loaded in an iframe from another origin. A positive result is the page rendering inside the frame, which makes clickjacking and cross frame scripting chains possible.
  3. Double-submit forms. Look for flows where the server returns a pre-filled form after a failed validation, then requires a second user action. A positive result is a two-step flow where the second step carries a server-issued token into an attacker-chosen request.
  4. Token scope. Check whether a token issued for one form or session is accepted for another action. A positive result is a token from a low-value form being accepted on a sensitive endpoint.
  5. Frame-busting gaps. Where frame-busting scripts exist, test whether they can be bypassed with sandboxed frames or nested frames. A positive result is the protected page still rendering and accepting clicks.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher found a way to make a website send a message on behalf of a logged-in user who clicks "Post Message" on a page the attacker controls. The website had a protection in place that was supposed to stop exactly this kind of trick, and the protection did work in the obvious case. The researcher found that removing the token still returned a form with a valid token, and combined that with cross frame scripting.

The two weaknesses are:

  • Cross-site request forgery (CSRF): a trick where an attacker's page makes a victim's browser send a request to another site, using the victim's existing login. The site sees a request coming from the victim's browser with the victim's cookies attached, so it treats it as legitimate.
  • Cross frame scripting: the ability to load another site's pages inside frames (windows within a window) on an attacker's page, and to interact with them. This is the foundation of clickjacking, where the attacker positions invisible or disguised content so the victim clicks something they did not intend to click.

CSRF was not possible on its own because of the token, but chaining the token-reflecting response with cross frame scripting let the attacker send a message as the victim. The researcher reported it to the program on HackerOne and received a bounty reward.

A quick note on the platform: HackerOne is a website where companies publish programs inviting researchers to test their systems and report problems. A public program is one that anyone can join. The report does not name the program or the application involved.

The feature that was targeted

The application had a module that lets a user send messages to other users. The researcher describes it as a form with a "Post Message" action, and the write-up opens with a screenshot of that form.

Send Message Form From the original on medium.com

Send Message Form

A form is the part of a web page where you type information (a message, a name, a comment) and press a button to submit it. When you press the button, your browser packages up what you typed and sends it to the server. A server is the computer that runs the website and stores its data; your browser (the client) talks to it over the internet.

The goal was to send a message on behalf of a logged-in victim. In other words, the attacker wanted the victim's own browser to submit the form with the attacker's chosen content, without the victim realising.

The setup

The write-up does not describe accounts, roles, versions or a test environment. The only tool named is Burp, short for Burp Suite, a program security researchers use to watch and modify the traffic between a browser and a website. One of its features generates a CSRF proof of concept (PoC): a small HTML page that, when opened in a browser, automatically submits a chosen request to the target site. It is a ready-made attack page for testing whether CSRF is possible.

Two preconditions matter for the attack:

  1. The victim must be logged in to the application. A login works by the server giving the browser a session cookie, a small piece of data the browser stores and sends back with every request to that site. The cookie is how the server recognises "this is the same person who logged in earlier". If the attacker can make the victim's browser send a request, the cookie goes along with it automatically.
  2. The application must be frameable, meaning another site can load its pages inside an iframe. An iframe is an HTML element that embeds one web page inside another, like a picture frame on a wall holding a different picture. The whole chain depends on this, because the attack needs the application's pages to appear inside the attacker's page.

Finding it

The researcher first tested the send-message module for CSRF directly. That path was closed: the POST request carried a token which the server validated, so a forged request without a valid token was rejected.

A POST request is one of the ways a browser sends data to a server. When you submit a form, the browser typically sends a POST request with your typed values in the request body. A CSRF token is a random value the server puts into the form when it renders the page. When the form is submitted, the browser sends the token back, and the server checks that it matches the one it issued. An attacker's page cannot read the token from the victim's browser (because of browser rules that stop one site reading another site's pages), so a forged request without the correct token is refused. This is the standard defence against CSRF.

The interesting behaviour appeared when the CSRF PoC generated in Burp was executed with the CSRF token removed. Instead of an error, the server responded with the same form values and a new CSRF token set in the new message form, returned as the response body. In other words, the server handed back a freshly rendered form, pre-filled with the submitted values and carrying a valid token.

That changes the picture. If the victim then clicks "Post Message" on that returned form, the request goes to the server with the form values already set by the server and with the valid token, and the request is executed successfully. The missing piece was getting the victim to make that click on the attacker's terms, and the researcher found it: the entire web application was vulnerable to cross frame scripting.

Exploitation

The attack chains two issues: the CSRF PoC that gets a valid token back from the server, and cross frame scripting, which lets the attacker load and interact with the application's pages inside an attacker page.

Step 1: build the CSRF PoC without the token

Generate a CSRF PoC in Burp for the send-message request, fill in the form values, and remove the CSRF token. The report does not reproduce the request or the PoC markup.

Why this step: the researcher wanted to see what the server does when a form submission arrives without the token. Normally the answer should be a flat rejection. Removing the token is the simplest way to test that.

Step 2: observe the server's response

When the PoC is executed, the server responds with all form values pre-set in the response and also with a valid token. The response is a new message form, ready to submit.

Why this matters: the server did not reject the request. It treated the failed submission as a reason to show the form again, with the submitted values filled in and a brand-new valid token embedded. The token was supposed to be a barrier, but here the server hands a fresh one back to whoever asks. The attacker cannot read that response directly from their own page, but if the response is loaded inside a frame on the attacker's page, the attacker can position the victim's click on it.

Step 3: embed the CSRF file inside the clickjacking file

Because the application is vulnerable to cross frame scripting, the attacker includes the CSRF file inside the clickjacking file. The clickjacking page loads the CSRF file, which auto-submits the form with the chosen values.

CSRF File In Clickjacking From the original on medium.com

CSRF File In Clickjacking

Why this step: the CSRF file is the page that automatically submits the form. The clickjacking file is the outer page the victim actually visits. By loading the CSRF file inside a frame of the clickjacking page, the attacker controls what the victim sees and where the victim's clicks land.

Step 4: the server returns a token-bearing form

The server answers the auto-submitted request with the same form values set and a valid CSRF token, as in step 2.

Why this step: this is the same behaviour observed in step 2, now happening inside the attacker's frame. The response is a form pre-filled with the attacker's chosen message and carrying a valid token, ready to be submitted for real.

Step 5: get the victim's click

The victim opens the malicious URL sent by the attacker. The clickjacking file loads the CSRF file, which auto-submits the form, and the response, the pre-filled form with a valid token, is loaded inside the clickjacking frame. When the victim clicks "Post Message", a valid request is generated and executed successfully.

Chaining CrossFrameScripting and CSRF From the original on medium.com

Chaining CrossFrameScripting and CSRF

Why this step: the final submission needs a real click from the victim, because the attacker cannot press the button for them. The clickjacking page arranges things so that the victim's click lands on the "Post Message" button of the pre-filled form. The victim clicks "Post Message" on the pre-filled form loaded in the clickjacking frame, and the request is executed successfully.

The researcher's own summary of the scenario:

  1. The attacker will generate a valid csrf poc with burp with form values and removing csrf token.
  2. Now if we execute the csrf poc server will respond with all form values pre set in the response and also with a valid token, Hence an attacker will include the csrf file inside clickjacking file.
  3. So when the victim clicks on the malicious url sent by attacker, the clickjacking file will load the csrf file and inturn it would auto submit the form with the respective values and later server will send a response with the same form values set and also with the valid csrf token. Hence now the response is loaded using clickjacking and when the user clicks on Post Message it would generate a valid request and it will be executed successfully.

A video PoC is linked in the report: https://www.youtube.com/watch?v=cjp0ZcgscPA

Or watch on YouTube
From the original on medium.com

Root cause

The token check itself worked: a request without a valid token was not accepted. The weakness is in how the server handles a request that fails that check. Rather than rejecting it, it re-renders the message form with the submitted values and a fresh valid token. That turns the token from a barrier into something the attacker can obtain through the victim's own browser, because the response is delivered to a page the attacker controls through framing.

A useful comparison: imagine a bank teller who refuses to process a withdrawal without the correct signed slip, but when you hand over a blank slip, the teller fills it in with the amount you asked for and signs it for you. The check is technically in place, but the way the failure is handled defeats it.

The second half of the chain is the absence of frame protection. The report states that the entire web application was vulnerable to cross frame scripting, which is what allows the attacker's page to load the application, let the form auto-submit, and then place the returned form under the victim's cursor.

Impact

An attacker could send a message as a logged-in victim, with content chosen by the attacker, provided the victim visits the attacker's page and clicks the "Post Message" control as positioned by the attacker. The researcher submitted the vulnerability and received a bounty reward.

The broader point the author makes is about chaining: cross frame scripting on its own is often treated as low impact and skipped as out of scope, but combined with the token-reflecting form behaviour it produced a working CSRF bypass. In the author's words, no vulnerability is low if we try to chain it with a few others, and low hanging fruits can give a great impact when used in a unique way.

Fix

Based on the behaviour described, the token check should reject a request with a missing or invalid token outright, without re-rendering the form with the submitted values and a new token. Separately, the application should not be frameable by third-party origins, for example through frame-ancestors or X-Frame-Options, which removes the cross frame scripting half of the chain.

A word on those two headers, since they are the standard tools here. X-Frame-Options is a response header a server can send to tell the browser whether the page may be shown inside a frame, and by whom. frame-ancestors is a directive in the Content-Security-Policy header that does the same job in a more flexible way, listing which origins are allowed to frame the page. Either one, correctly configured, stops the attacker's page from loading the application inside a frame, and without the frame the clickjacking half of the chain collapses.

Variants to test

These are the same checks a researcher would try on other applications, written for someone starting out.

  1. Token-reflecting error pages. Submit a state-changing form without its token and inspect the response. A positive result is a response body that contains the submitted values plus a fresh valid token, which can then be re-submitted. In plain terms: look at what the site sends back when you deliberately leave the token out. If it sends back a new token along with your values, that is the same gap described here.
  2. Framing on any authenticated page. Check whether the application can be loaded in an iframe from another origin. A positive result is the page rendering inside the frame, which makes clickjacking and cross frame scripting chains possible. In plain terms: build a tiny local HTML page with an iframe pointing at the site while logged in, and see whether the site appears inside it.
  3. Double-submit forms. Look for flows where the server returns a pre-filled form after a failed validation, then requires a second user action. A positive result is a two-step flow where the second step carries a server-issued token into an attacker-chosen request. In plain terms: any place where the site says "that did not work, here is the form again with your values" is worth a second look.
  4. Token scope. Check whether a token issued for one form or session is accepted for another action. A positive result is a token from a low-value form being accepted on a sensitive endpoint. In plain terms: a token should be tied to the specific action it was issued for, not usable anywhere.
  5. Frame-busting gaps. Where frame-busting scripts exist, test whether they can be bypassed with sandboxed frames or nested frames. A positive result is the protected page still rendering and accepting clicks. In plain terms: some sites try to break out of frames with JavaScript; that defence can sometimes be worked around, so it is worth testing rather than assuming it holds.

Glossary

  • API: a defined way for one piece of software to talk to another, like a menu of requests a service accepts and the answers it gives.
  • Bounty: a reward, usually money, paid by a company to a researcher who reports a valid security problem.
  • Browser: the program you use to view web pages, such as Chrome, Firefox or Safari.
  • Burp (Burp Suite): a tool researchers use to intercept, inspect and modify traffic between a browser and a website.
  • Clickjacking: an attack where a victim is tricked into clicking something on a page they did not intend to interact with, usually by hiding or disguising it.
  • Client: the program on the user's side, normally the browser, that sends requests to a server.
  • Content-Security-Policy: a response header that tells the browser which sources of content and which framing are allowed for a page.
  • Cookie: a small piece of data a site stores in the browser and receives back on later requests, commonly used to keep a user logged in.
  • Cross frame scripting: the ability to load another site's pages inside frames on an attacker's page and interact with them.
  • CSRF (cross-site request forgery): an attack where an attacker's page causes a victim's browser to send a request to another site using the victim's existing login.
  • CSRF PoC (proof of concept): a small HTML page that automatically submits a chosen request to a target site, used to test for CSRF.
  • CSRF token: a random value placed in a form by the server and checked on submission, used to prove the request came from the site's own page.
  • Endpoint: a specific URL on a server that accepts requests and performs an action.
  • Form: the part of a web page where a user types information and submits it to the server.
  • frame-ancestors: a Content-Security-Policy directive that lists which origins are allowed to embed the page in a frame.
  • HackerOne: a platform where companies publish programs inviting researchers to test their systems and report problems.
  • HTML: the language web pages are written in, describing their structure and content.
  • iframe: an HTML element that embeds one web page inside another.
  • Impact: the real-world consequence of a vulnerability, such as what an attacker can do or whose data is affected.
  • JavaScript: the programming language that runs in the browser and makes pages interactive.
  • Origin: the combination of scheme, host and port that identifies a website, used by browsers to decide what one site may access on another.
  • POST request: a request that sends data to the server, typically used when submitting a form.
  • Public program: a bug bounty program that anyone can join and submit reports to.
  • Response body: the content the server sends back, such as the HTML of a page.
  • Root cause: the underlying reason a vulnerability exists, as opposed to its visible symptom.
  • Server: the computer that runs a website, stores its data and answers requests from browsers.
  • Session: a period during which the server recognises a user as logged in, usually tracked by a session cookie.
  • Token: a value issued by the server and checked on later requests to prove the request is legitimate.
  • X-Frame-Options: a response header that tells the browser whether a page may be displayed inside a frame.

More by Mr.Hacker

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.