Stealing Chat session ID with CORS and execute CSRF attack
A chat endpoint that creates chat sessions lacked CORS and CSRF protections, so a malicious page could read a victim's chat session ID. That ID could then be used in a CSRF request to send chat messages as the victim.
Published on sunilyedla.medium.com
Hello Everyone, Hope you all are healthy and safe. Today’s writeup is my recent find on Bugcrowd private program.
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.
Context
This write-up covers a finding on a Bugcrowd private program. The target application, whose domain is redacted in the report, has a built-in chat feature. When a user sends a new message, the system issues a POST request to a chat endpoint that is scoped to a particular chat session.
The interesting part is the shape of that endpoint: the chat session ID is part of the URL path, so any request that sends a message has to know the victim's session ID first. The report describes the ID format as follows:
XXXXXX-CHAT_XXXXXXXXXX–XXXX-XXXX-XXXX-XXXXXXXXXXXX
The researcher's goal became twofold: find a way to obtain a victim's chat session ID, then use it to send messages as that victim.
Setup
The report does not describe any accounts, roles, tooling versions or test environment. The work was done against a private Bugcrowd program in the second week of January 2021, and the only tooling shown is a small HTML proof of concept built on XMLHttpRequest. The precondition for the attack is that a victim user is logged in to the target application and visits a page controlled by the attacker.
Finding it
While exploring the redacted domain, the researcher noticed the chat feature and captured the request the application sends when a new message is posted:
POST /ha/chat/<Chat_Session_ID> HTTP/1.1
Host: <redacted>
User-Agent: XXXXX
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json;charset=utf-8
Host-Site: XXX
Content-Length: 75
Origin: XXXXX
Connection: close
Referer: XXXXXXX
{“content”:”HI”,”event”:”MESSAGE”,”clientSideSequence”:4,”role”:”CUSTOMER”}
The body is JSON carrying the message content, an event type of MESSAGE, a client-side sequence number and a role of CUSTOMER. The session identifier sits in the path.
Testing showed that this POST request is vulnerable to CSRF, which on its own would let an attacker send messages on behalf of a victim user. The obstacle is the path parameter: to forge the request the attacker must already know the victim's chat session ID, and the ID is not something the attacker can guess from the format alone.
Rather than stop there, the researcher kept exploring and found an endpoint that creates a chat session ID for the user:
https://<redacted>/ha/chat/create
This endpoint, unlike the messaging endpoint, was found to lack CORS and CSRF protection. The report says the create endpoint lacks CORS and CSRF protection, and the researcher verified it was vulnerable to CORS.
Exploitation
Step 1: Confirm the CORS misconfiguration on the create endpoint
The researcher wrote a CORS proof of concept and verified that the create endpoint is vulnerable to CORS. The screenshot below shows that verification.

The proof of concept code given in the report is:
<html>
<script>
var req = new XMLHttpRequest(); req.onload = reqListener; req.open(‘GET/POST’,’<Vulnerable URL>’,true); req.withCredentials = true;
req.send(‘{}’); function reqListener() { alert(this.responseText); };
</script>
</html>
The important parts are withCredentials = true, which makes the browser attach the victim's cookies to the cross-origin request, and the reqListener callback, which reads this.responseText. Reading the response body from a cross-origin request only works if the server returns CORS headers that authorise the attacker's origin and allow credentials. The report notes that the method and URL in the snippet should be changed to match the target.
Step 2: Steal the chat session ID
The researcher's plan was to use the CORS-readable create endpoint to obtain the victim's chat session ID, then use it in the CSRF request.
Step 3: Send messages as the victim
Armed with the stolen session ID, the attacker builds the CSRF request against the messaging endpoint, placing the ID in the path and the JSON message body in the request, exactly as the application does. Because that endpoint has no CSRF protection, the forged request is accepted and the message is attributed to the victim user.
Root cause
Two separate weaknesses combine here. The chat creation endpoint was found to lack CORS and CSRF protection, so a cross-origin page could read its response. The messaging endpoint accepts state-changing POST requests without CSRF protection, so a cross-origin request carrying the victim's cookies is honoured. Either flaw alone would be limited; together they let an attacker both learn the secret in the URL and use it. The report does not describe the server-side implementation, so the exact origin-checking logic behind the CORS behaviour is not shown.
Impact
An attacker who can get a logged-in victim to load a malicious page can steal that victim's chat session ID and then send chat messages as the victim. The report frames the impact as sending messages on behalf of victim users.
Fix
The fixes implied by the two flaws are to restrict CORS on the chat creation endpoint so that only trusted origins are allowed and credentials are not exposed to arbitrary origins, and to add CSRF protection to the messaging endpoint so that state-changing requests cannot be forged from another site.
Variants to test
- Look for endpoints that mint identifiers used in other endpoints' paths, such as session, conversation or resource creation calls, and test them with an
Originheader from a controlled domain plus credentials. A positive result is anAccess-Control-Allow-Originreflecting your origin together withAccess-Control-Allow-Credentials: true, and a readable response body in the browser. - Test state-changing endpoints that take an identifier in the path for CSRF by submitting the same request from a cross-origin page with the victim's cookies. A positive result is the action being performed without any token check.
- Chain the two: use a CORS-readable creation endpoint to obtain the identifier, then replay it against the unprotected action endpoint. A positive result is an action attributed to the victim account.
- Try both
GETandPOSTagainst the creation endpoint, as the proof of concept does, since a permissive CORS policy may apply to either method.
The report was raised on Bugcrowd on Jan/12/2021 and triaged by the Bugcrowd triage team with severity P3 on Jan/26/2021.

What happened, in plain words
A security researcher was looking around a website that was part of a private bug bounty program on Bugcrowd. A bug bounty program is an arrangement where a company invites independent researchers to look for security problems in its systems and report them, often for a reward. "Private" means only invited researchers can take part.
The website had a chat feature built in, like the message box you might see on a shopping site where you talk to a support agent. The researcher found two separate weaknesses in how that chat worked and described how chaining them could let an attacker obtain a victim's chat session ID and then send messages as that person.
A chat session ID is a long string of characters that identifies one particular conversation. Think of it like a coat-check ticket: the number on the ticket is how the cloakroom knows which coat is yours. If someone else gets your ticket number, they can collect your coat. Here, the "ticket number" sits in the web address the browser uses when it sends a message, so anyone who knows it can act on that conversation.
The two weaknesses were:
- The endpoint that sends a chat message had no CSRF protection. CSRF stands for Cross-Site Request Forgery. It is a trick where a malicious website makes your browser send a request to another site where you are already logged in, and that other site cannot tell the request was not really your idea.
- The endpoint that creates a chat session had a CORS misconfiguration. CORS stands for Cross-Origin Resource Sharing. It is a set of rules, enforced by your browser, about whether a page from one website is allowed to read responses from another website. When it is misconfigured, a page on an attacker's site can read data from the victim site, including data that belongs to the logged-in user.
The researcher reported the finding to Bugcrowd on 12 January 2021, and the Bugcrowd triage team (the people who first check and rate incoming reports) triaged it with severity P3 on 26 January 2021. Severity P3 is a middle rating on Bugcrowd's scale.
Background you need first
Before walking through the steps, here are the ideas the rest of the article relies on. Each one is explained from scratch.
Websites, pages and origins
When you type an address into your browser, the browser fetches a page from a server and shows it to you. The address has parts: the scheme (https), the host (example.com) and sometimes a port number. The combination of scheme, host and port is called an origin. Two pages have the same origin only if all three parts match. https://shop.example.com and https://mail.example.com are different origins even though they share a domain, because the hosts differ.
Origins matter because browsers use them as a security boundary. By default, a page from one origin is not allowed to read data from another origin. This rule is called the same-origin policy. It is what stops a random website you visit from quietly reading your webmail in another tab.
Cookies and being logged in
When you log in to a website, the server usually gives your browser a small piece of data called a cookie. Your browser stores it and sends it back automatically with every later request to that same site. That is how the site recognises you on the next page load: the cookie is your proof that you already logged in. You do not have to type your password again for every click.
The important consequence: if your browser is tricked into sending a request to that site, it will attach your cookie without asking you. The site will see a request that looks exactly like one you made yourself.
APIs and endpoints
An API (Application Programming Interface) is the set of addresses a website's own pages use to talk to its server behind the scenes. Each address is called an endpoint. When you click "send" in a chat box, the page does not reload; it quietly sends a request to an endpoint, and the server replies with data, usually in a format called JSON (JavaScript Object Notation), which is just text structured with curly braces, quotes and colons.
A POST request is one kind of request a browser can make. GET is used to ask for something ("give me this page"), while POST is used to send something ("here is a new message, save it"). A request has a path, the part of the address after the host, and optionally a body, the data being sent.
What CSRF is
Imagine a form at your bank that transfers money, and the bank only checks that you are logged in, not that you actually meant to press the button. A malicious site could include a hidden form that submits itself to the bank the moment you load it. Your browser attaches your bank cookie, the bank sees a logged-in request, and the transfer happens. That is CSRF.
The defence is a CSRF token: a secret value that the real page includes with each request, which an attacker's page cannot know. If the endpoint does not check for one, the request can be forged from anywhere.
What CORS is
Because of the same-origin policy, a page on attacker.example cannot normally read the response from victim.example. But sometimes sites legitimately need to allow it, for example when a company runs its front end and API on different hosts. CORS is the mechanism for granting that permission. The server sends special response headers, such as Access-Control-Allow-Origin, saying which other origins may read its responses.
There is a catch with cookies. If a cross-origin request should carry the user's cookies, the browser only sends them when the script sets a flag called withCredentials to true, and the server must explicitly agree by also sending Access-Control-Allow-Credentials: true. If a server says "any origin may read this, and credentials are fine", then any website the victim visits can read that user's data from the server. That is a CORS misconfiguration.
The target and its chat feature
The target application, whose domain is redacted in the report, has a built-in chat feature. When a user sends a new message, the system issues a POST request to a chat endpoint that is scoped to a particular chat session. "Scoped to" means the endpoint is tied to one specific conversation, and the way it knows which one is that the session ID is part of the URL path.
The report describes the ID format as follows:
XXXXXX-CHAT_XXXXXXXXXX–XXXX-XXXX-XXXX-XXXXXXXXXXXX
In other words, the ID is a long, structured string. The Xs stand for characters that were blanked out. The point of showing the format is that the session ID is part of the URL path, so the attacker needs to know it.
So the researcher's goal became twofold: first find a way to obtain a victim's chat session ID, then use it to send messages as that victim.
Setup
The report does not describe any accounts, roles, tooling versions or test environment. The work was done against a private Bugcrowd program in the second week of January 2021, and the only tooling shown is a small HTML proof of concept built on XMLHttpRequest, which is a built-in browser feature that lets a page send requests and read the replies from JavaScript.
The precondition for the attack is that a victim user is logged in to the target application and visits a page controlled by the attacker. That is the standard setup for both CSRF and CORS attacks: the attacker cannot reach into the victim's browser directly, so the victim has to be lured to a page the attacker controls, and from there the victim's own browser does the work.
Finding it
While exploring the redacted domain, the researcher noticed the chat feature and captured the request the application sends when a new message is posted:
POST /ha/chat/<Chat_Session_ID> HTTP/1.1
Host: <redacted>
User-Agent: XXXXX
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json;charset=utf-8
Host-Site: XXX
Content-Length: 75
Origin: XXXXX
Connection: close
Referer: XXXXXXX
{“content”:”HI”,”event”:”MESSAGE”,”clientSideSequence”:4,”role”:”CUSTOMER”}
Line by line, in plain words:
POST /ha/chat/<Chat_Session_ID> HTTP/1.1is the request line. It says: send data (POST) to the path/ha/chat/followed by the chat session ID, using version 1.1 of the HTTP protocol, the language browsers and servers speak.Host: <redacted>names the server being contacted. The actual domain was removed from the report.User-Agent: XXXXXis where the browser normally identifies itself. The value was blanked out.Accept: application/json, text/plain, */*tells the server which reply formats the client can handle: JSON, plain text, or anything.Accept-Language: en-US,en;q=0.5says the client prefers US English.Accept-Encoding: gzip, deflatesays the client can accept compressed replies, to save bandwidth.Content-Type: application/json;charset=utf-8says the body being sent is JSON text encoded in UTF-8, a common character encoding.Host-Site: XXXis a custom header specific to this application. Its value was blanked out.Content-Length: 75says the body is 75 bytes long, so the server knows where it ends.Origin: XXXXXnormally tells the server which site the request came from. The value was blanked out.Connection: closeasks the server to close the network connection after replying.Referer: XXXXXXXnormally says which page the request was made from. The value was blanked out.- After the blank line comes the body:
{“content”:”HI”,”event”:”MESSAGE”,”clientSideSequence”:4,”role”:”CUSTOMER”}. This is JSON carrying the message content (HI), an event type ofMESSAGE, a client-side sequence number (4, a counter the page uses to keep messages in order) and a role ofCUSTOMER, meaning the sender is the customer side of the conversation. The session identifier sits in the path, not in the body.
Testing showed that this POST request is vulnerable to CSRF, which on its own would let an attacker send messages on behalf of a victim user. That is already a real problem: forged messages would appear to come from the victim.
The obstacle is the path parameter. To forge the request, the attacker must already know the victim's chat session ID, and the ID is not something the attacker can guess from the format alone. This is why the researcher did not stop at the CSRF finding: a CSRF attack that cannot name the right conversation is useless.
Rather than stop there, the researcher kept exploring and found an endpoint that creates a chat session ID for the user:
https://<redacted>/ha/chat/create
This endpoint, unlike the messaging endpoint, was found to lack CORS and CSRF protection. The report says the create endpoint lacks CORS and CSRF protection, and the researcher verified it was vulnerable to CORS. In everyday terms, the first endpoint hands out the coat-check ticket to anyone who asks, and the second endpoint accepts the ticket from anyone who presents it.
Exploitation
Step 1: Confirm the CORS misconfiguration on the create endpoint
The researcher wrote a CORS proof of concept and verified that the create endpoint is vulnerable to CORS. A proof of concept is a small, deliberately harmless demonstration that a weakness is real, rather than just suspected. The screenshot below shows that verification.

The proof of concept code given in the report is:
<html>
<script>
var req = new XMLHttpRequest(); req.onload = reqListener; req.open(‘GET/POST’,’<Vulnerable URL>’,true); req.withCredentials = true;
req.send(‘{}’); function reqListener() { alert(this.responseText); };
</script>
</html>
Line by line, in plain words:
<html>and</html>mark the start and end of a web page.<script>and</script>mark the start and end of a block of JavaScript, the programming language browsers run.var req = new XMLHttpRequest();creates a request object, a little tool inside the browser that can send requests and receive replies without reloading the page.req.onload = reqListener;says: when the reply arrives, run the function calledreqListener.req.open(‘GET/POST’,’<Vulnerable URL>’,true);prepares the request. The first slot is the method, shown here as a placeholderGET/POSTbecause the researcher had to pick whichever the target accepted. The second slot is the address to call, shown as a placeholder<Vulnerable URL>. Thetruemeans do it in the background, without freezing the page.req.withCredentials = true;is the crucial line. It tells the browser to attach the victim's cookies to this cross-origin request. Without it, the request would arrive at the server as an anonymous visitor and would not act as the logged-in user.req.send(‘{}’);actually sends the request, with an empty JSON object{}as the body.function reqListener() { alert(this.responseText); };is the function that runs when the reply arrives.this.responseTextis the reply body as text, andalert(...)pops it up in a dialog box so the researcher can see it. If the dialog shows the server's data, the browser was allowed to read a cross-origin response, which is exactly the misconfiguration being tested.
The important parts are withCredentials = true, which makes the browser attach the victim's cookies to the cross-origin request, and the reqListener callback, which reads this.responseText. Reading the response body from a cross-origin request only works if the server returns CORS headers that authorise the attacker's origin and allow credentials. The report notes that the method and URL in the snippet should be changed to match the target.
Step 2: Steal the chat session ID
The researcher's plan was to use the CORS-readable create endpoint to obtain the victim's chat session ID, then use it in the CSRF request. Sending it back is just a matter of the script making one more request, this time to a server the attacker controls, with the stolen ID in it.
Step 3: Send messages as the victim
Armed with the stolen session ID, the attacker builds the CSRF request against the messaging endpoint, placing the ID in the path and the JSON message body in the request, exactly as the application does. Because that endpoint has no CSRF protection, the forged request is accepted and the message is attributed to the victim user. To the people reading the chat, the message looks like it came from the victim.
Root cause
Two separate weaknesses combine here. The chat creation endpoint was found to lack CORS and CSRF protection, so a cross-origin page could read its response. The messaging endpoint accepts state-changing POST requests without CSRF protection, so a cross-origin request carrying the victim's cookies is honoured. Either flaw alone would be limited; together they let an attacker both learn the secret in the URL and use it. The report does not describe the server-side implementation, so the exact origin-checking logic behind the CORS behaviour is not shown.
Impact
An attacker who can get a logged-in victim to load a malicious page can steal that victim's chat session ID and then send chat messages as the victim. The report frames the impact as sending messages on behalf of victim users.
Fix
The fixes implied by the two flaws are to restrict CORS on the chat creation endpoint so that only trusted origins are allowed and credentials are not exposed to arbitrary origins, and to add CSRF protection to the messaging endpoint so that state-changing requests cannot be forged from another site.
Variants to test
If you want to look for similar problems yourself, here are the same ideas written as things to try. Each one names what a positive result looks like, so you know when you have found something.
- Look for endpoints that mint identifiers used in other endpoints' paths, such as session, conversation or resource creation calls, and test them with an
Originheader from a controlled domain plus credentials. A positive result is anAccess-Control-Allow-Originreflecting your origin together withAccess-Control-Allow-Credentials: true, and a readable response body in the browser. - Test state-changing endpoints that take an identifier in the path for CSRF by submitting the same request from a cross-origin page with the victim's cookies. A positive result is the action being performed without any token check.
- Chain the two: use a CORS-readable creation endpoint to obtain the identifier, then replay it against the unprotected action endpoint. A positive result is an action attributed to the victim account.
- Try both
GETandPOSTagainst the creation endpoint, as the proof of concept does, since a permissive CORS policy may apply to either method.
The report was raised on Bugcrowd on Jan/12/2021 and triaged by the Bugcrowd triage team with severity P3 on Jan/26/2021.

Glossary
- API: the set of addresses a website's own pages use to talk to its server behind the scenes.
- Bug bounty program: an arrangement where a company invites independent researchers to find and report security problems, often for a reward.
- Bugcrowd: the platform that hosted this private program and whose triage team rated the report.
- Chat session ID: a long string that identifies one particular chat conversation, used in the URL to tell the server which conversation a request belongs to.
- Cookie: a small piece of data a site stores in your browser after you log in, sent back automatically with later requests so the site recognises you.
- CORS (Cross-Origin Resource Sharing): browser-enforced rules, set by response headers from the server, about whether a page from one origin may read responses from another origin.
- CORS misconfiguration: a server setting that lets arbitrary origins read its responses, especially when credentials are also allowed.
- CSRF (Cross-Site Request Forgery): a trick where a malicious site makes your browser send a request to another site where you are logged in, and that site treats it as your own action.
- CSRF token: a secret value included with legitimate requests that an attacker's page cannot know, used to block forged requests.
- Endpoint: one specific address on a server that a page can send requests to.
- GET: a request method used to ask for something, such as a page or data.
- JSON (JavaScript Object Notation): a text format for structured data, using curly braces, quotes and colons.
- Origin: the combination of scheme, host and port in a web address; the boundary browsers use to decide what may read what.
- Path: the part of a web address after the host, such as
/ha/chat/create. - POST: a request method used to send data to the server, such as a new chat message.
- Proof of concept: a small, deliberately harmless demonstration that a weakness is real.
- Same-origin policy: the browser rule that a page from one origin may not read data from another origin by default.
- Severity P3: a middle rating on Bugcrowd's severity scale.
- Triage: the first check of an incoming report, where it is confirmed and rated.
- withCredentials: a flag on a browser request that makes the browser attach the user's cookies to a cross-origin request.
- XMLHttpRequest: a built-in browser feature that lets a page send requests and read replies from JavaScript without reloading.