CSRF CSRF CSRF
Several web application actions (adding a public wishlist to a cart, deleting a bookmark, deleting a phone number, changing communication settings, and deleting a favourite list) lacked CSRF tokens or had weak referer checks, allowing an attacker to make a victim perform these actions unknowingly. The impact was low, such as spamming a cart or deleting data, but some were rewarded.
The first functionality where i had found CSRF was adding all products of some public wish-list in to your cart.
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 collects four cross-site request forgery (CSRF) findings from private bug bounty programs. None of them is high impact on its own, but each was enough to earn a payment or swag, and the point of the article is to show beginners which kinds of functionality and actions tend to be vulnerable to CSRF in a web application. The targets are described only generically: a shopping site with public wish-lists, a site with a bookmark deletion feature, a HackerOne private program whose front end talks to an API, and a site with a favourites list for articles. The author is Navneet (@na5n33t).
Setup
No special tooling, accounts or versions are described. Each finding came from ordinary use of the feature while watching the requests it produced, and in the second case from reasoning about which header was blocking the forgery. The preconditions that matter are the ones built into each feature: a public wish-list that another user can copy, a delete action protected only by a referer check, an API-backed site where most actions carry an auth header, and a favourites list with a delete button.
Finding it
The common thread is a state-changing action that a browser can be made to trigger on behalf of a logged-in victim. The author looked at the request each button produced and asked two questions: does it change state, and is there anything in the request that a third-party site cannot supply? A CSRF token in a header or body, or a check on a header the attacker cannot control, is what stops the attack. Where neither was present, the action was forgeable.
Exploitation
1. CSRF to spam the shopping cart
The site let a user add another user's public wish-list to their own cart. User A adds products to a wish-list and makes it public; user B sees it and clicks an add to cart button, which copies the whole list into B's cart.
The button issued a simple HTTP GET request:
https://www.SomeWebsite.com/xyz?some_page=wishlist&move_all=true&w_id=1337&public_cid=31337
There was no HTTP header carrying a CSRF token, and none of the parameters protected the request from CSRF. Because the action is a GET with no secret value, an attacker can build a large wish-list, make it public, and then get a victim's browser to load that URL, filling the victim's cart with the attacker's products.
The issue was fixed within a day and paid $25.
2. Bypass of CSRF protection to delete a bookmark
The second finding was in the feature that lets a user delete a bookmarked job. The delete button also made a GET request, but the straightforward forgery did not work. The author suspected the referer header was protecting the request, and tried the bypass where the attacker's own site reproduces the victim's path in its URL:
myCSRFwebsite.com/www.victimWebsite.com/abc/xyz/csrf.html
The site checked the referer header for the string www.victimWebsite.com/abc/xyz/csrf.html. Because the attacker's site can contain folders matching that string, the check passed and the CSRF succeeded. The full bypass is written up separately at https://medium.com/bugbountywriteup/critical-bypass-csrf-protection-on-ibm-313ffb68dd0c.
Despite demonstrating that the protection could be bypassed, the author received only $25.
3. CSRF disguised in APIs
In a HackerOne private program the whole site performed its actions through API calls. The author initially assumed CSRF was impossible, since every action-carrying API call included an auth header that protects the request. Looking at every request, however, turned up two endpoints that did not follow that pattern: one deletes a phone number and the other changes communication settings. They used GET and POST respectively, and neither had a CSRF token.
No bounty was paid for this one; the author received 14 reputation points on HackerOne and included it because it taught something new: it is worth checking every action, since some may not go through the API path and can be vulnerable to CSRF.
4. CSRF to delete a favourite list
A section of the site let users favourite articles, and a button deleted the favourite list. That action was a POST request with no CSRF token in it, so a CSRF attack could remove articles from a victim's favourites. The reward was a T-shirt.
Root cause
In each case the server accepted a state-changing request without a value that only the legitimate page could produce. The first and fourth findings had no token at all. The second relied on a referer check that looked for the victim's path in the header, which an attacker can reproduce in their own path. The third shows that an auth header on most calls does not protect endpoints that omit it. The report does not describe the server-side code, so these are inferences from the requests.
Impact
All four are low impact. An attacker can fill a victim's cart with products, delete a bookmarked job, delete a phone number or change communication settings, and remove articles from a favourites list, provided the victim visits the attacker's page while logged in. None of the findings gives access to data or account takeover.
Fix
The report says the first issue was fixed within a day; it does not describe the fix for the others. The general remedy is a per-session CSRF token checked on every state-changing request, including API endpoints, and rejecting state changes on GET. Referer checks should compare the full origin rather than a substring.
Variants to test
- Public or shareable lists with an add-all or copy action: look for a GET that carries only IDs. A positive result is the victim's cart or list changing after loading the URL.
- Delete buttons on bookmarks, favourites or saved items: check whether the request is GET or POST and whether a token is present. A positive result is the item disappearing from the victim's account.
- API-backed sites: enumerate every request, not just the ones through the main wrapper, and look for endpoints missing the auth header or token. A positive result is a state change from a cross-site request.
- Referer-based protection: host a page whose path mirrors the victim's URL and see whether the request is accepted. A positive result is the action succeeding from the attacker's domain.
- Settings and contact details: try changing communication preferences or deleting a phone number via forged requests. A positive result is the setting or number changing without the victim's action.
What happened, in plain words
This article is about a handful of cross-site request forgery (CSRF) bugs that Navneet (@na5n33t) found in private bug bounty programs. A bug bounty program is an arrangement where a company invites outside people to look for security problems in its systems and pays them for reporting the problems responsibly. A private program is one you can only join by invitation. None of these bugs is dramatic on its own, but each one was enough to earn a payment or some swag (a T-shirt, in one case). The aim is to show someone new to security which kinds of buttons and actions in a web application tend to be vulnerable to CSRF.
Before the individual findings, it helps to understand what CSRF actually is. When you log in to a website, the site usually gives your browser a small piece of data called a cookie, which the browser sends back with every request to that site. The cookie is how the site recognises you on the next page load, so you do not have to type your password again. The problem is that your browser will happily send that cookie to the site even when the request was triggered by a completely different website that you happen to be visiting. So if an attacker can make your browser send a request to the victim site, your cookie goes along with it, and the site treats the request as if you made it yourself. That is CSRF: tricking a logged-in user's browser into performing an action the user never intended.
A CSRF token is the usual defence. It is a random value that the legitimate page includes in each form or request, and the server checks it before doing anything. An attacker's page cannot know that random value, so the forged request fails. Some sites instead check the Referer header, which tells the server which page the request came from. If the referer is not the site's own page, the request is rejected. As the second finding shows, that check can be done badly.
The author's method throughout was simple: use the feature normally, watch the request the browser sends, and ask two questions. Does this request change something on the server (add to cart, delete, change a setting)? And is there anything in the request that a page on another website could not produce? If the answer to the first is yes and the second is no, the action is probably forgeable.
1. CSRF to spam the shopping cart
The first feature was a shopping site where users keep wish-lists. A wish-list is just a list of products a user is interested in. The site let a user make their wish-list public, so other users could see it, and it also let a user copy someone else's public wish-list into their own cart. The cart is the basket of things you intend to buy.
So the flow is: user A adds products to a wish-list and makes it public. User B visits that public wish-list and sees an "add to cart" button. Clicking it copies the whole list into B's cart.
The button sent a simple HTTP GET request. HTTP is the language browsers and servers use to talk to each other, and GET is the method used when you are just asking for a page or a resource. The request looked like this:
https://www.SomeWebsite.com/xyz?some_page=wishlist&move_all=true&w_id=1337&public_cid=31337
Line by line, in plain words:
https://www.SomeWebsite.com/xyzis the address of the page or handler on the server that does the work.- The
?starts the query string, which is the part of the URL that carries extra information to the server. some_page=wishlisttells the server which feature is involved: the wish-list.move_all=trueis the instruction to copy everything, not just one item.w_id=1337is presumably the identifier of a wish-list. The report does not explain what the abbreviation stands for.public_cid=31337is another identifier, presumably tied to the public copy of the list. Again, the report does not spell it out.
The important part is what was missing. There was no HTTP header carrying a CSRF token, and none of the parameters was a secret value that would stop a forgery. Everything needed to trigger the action is visible in the URL, and a URL is something an attacker can put anywhere: a link, an image tag, a redirect. So an attacker can build a big wish-list full of products, make it public, and then get a victim's browser to load that URL. The victim's cookie goes along, the server thinks the victim clicked the button, and the victim's cart fills up with the attacker's products.
This was fixed within a day and paid $25.
2. Bypass of CSRF protection to delete a bookmark
The second finding was in a feature that lets a user delete a bookmarked job. A bookmark here is a saved item, the same idea as a browser bookmark: something you want to come back to later.
The delete button also made a GET request, but the straightforward forgery did not work. Something was blocking it. The author suspected the Referer header, which the browser sends to tell the server which page the request came from. If the site checks that header and only accepts requests coming from its own pages, a request triggered from an attacker's page would be rejected.
So the author tried a bypass: build the victim's path into the attacker's own website address. The idea looks like this:
myCSRFwebsite.com/www.victimWebsite.com/abc/xyz/csrf.html
In plain words: the attacker controls myCSRFwebsite.com, and on that site creates folders named www.victimWebsite.com, then abc, then xyz, and puts a page called csrf.html inside. The full URL of that page now contains the string www.victimWebsite.com/abc/xyz/csrf.html as part of its path.
The victim site was checking the referer header for that string, not for the actual origin of the request. When the victim loaded the attacker's page, the browser sent a referer containing the matching string, the check passed, and the CSRF succeeded. The delete happened.
The full bypass is written up separately at https://medium.com/bugbountywriteup/critical-bypass-csrf-protection-on-ibm-313ffb68dd0c.
Despite showing that the protection could be bypassed, the author received only $25.
3. CSRF disguised in APIs
An API (application programming interface) is a way for one piece of software to talk to another. In a modern website, the pages you see are often just a shell, and every action you take, such as loading your profile or saving a setting, is sent as a separate request to an API behind the scenes. Those requests often carry an auth header, which is a value in the request that proves who is asking. Because a page on another website cannot read or set that header, an API call that requires it is naturally protected against CSRF.
This finding was in a HackerOne private program, where the whole site worked this way: every action went through API calls. The author's first thought was that CSRF would be impossible here, since every action-carrying call included the auth header. But looking at every request turned up two endpoints that did not follow the pattern. An endpoint is simply a specific address on the server that performs one job. One endpoint deleted a phone number, and the other changed communication settings. The first used a GET request and the second used a POST request. POST is the method used when you are sending data to the server to create or change something, as opposed to GET, which just asks for something. Neither request had a CSRF token.
So even on a site that looks fully API-driven, some actions may not carry the auth header and can be vulnerable. The lesson the author drew is to check every action, not just the ones that go through the usual path.
No bounty was paid for this one. The author received 14 reputation points on HackerOne. and included the finding because it taught something new.
4. CSRF to delete a favourite list
A section of the site let users favourite articles, the same idea as a like or a save. There was also a button to delete the favourite list. That action was a POST request with no CSRF token in it. Because POST requests can also be triggered from another site (for example by a form that submits automatically), a CSRF attack could remove articles from a victim's favourites.
The reward for this one was a T-shirt.
Why these worked
In each case the server accepted a request that changes something without requiring a value that only the legitimate page could produce. The first and fourth findings had no token at all. The second relied on a referer check that looked for the victim's path in the header, which an attacker can reproduce in their own path. The third shows that an auth header on most calls does not protect endpoints that omit it; those endpoints were probably left out of the common API wrapper. The report does not describe the server-side code, so these are inferences from the requests themselves.
How serious these are
All four are low impact. An attacker can fill a victim's cart with products, delete a bookmarked job, delete a phone number or change communication settings, and remove articles from a favourites list, provided the victim visits the attacker's page while logged in. None of the findings gives access to data or lets someone take over an account.
How to fix it
The general remedy is a per-session CSRF token checked on every state-changing request, including API endpoints, and rejecting state changes on GET. Referer checks should compare the full origin rather than a substring.
What to try yourself
- Public or shareable lists with an add-all or copy action: look for a GET that carries only IDs. A positive result is the victim's cart or list changing after loading the URL.
- Delete buttons on bookmarks, favourites or saved items: check whether the request is GET or POST and whether a token is present. A positive result is the item disappearing from the victim's account.
- API-backed sites: enumerate every request, not just the ones through the main wrapper, and look for endpoints missing the auth header or token. A positive result is a state change from a cross-site request.
- Referer-based protection: host a page whose path mirrors the victim's URL and see whether the request is accepted. A positive result is the action succeeding from the attacker's domain.
- Settings and contact details: try changing communication preferences or deleting a phone number via forged requests. A positive result is the setting or number changing without the victim's action.
Glossary
- API: a way for software to talk to other software; in a website, the part that performs actions behind the scenes.
- Auth header: a value in a request that proves who is asking, which a page on another site cannot set.
- Bookmark: a saved item a user wants to come back to later.
- Bug bounty program: an arrangement where a company pays outside people for reporting security problems responsibly.
- Cart: the basket of products a shopper intends to buy.
- Cookie: a small piece of data a site stores in your browser and gets back with each request, used to recognise you.
- CSRF (cross-site request forgery): tricking a logged-in user's browser into sending a request the user did not intend.
- CSRF token: a random value included in a legitimate request and checked by the server, which an attacker cannot guess.
- Endpoint: a specific address on a server that performs one job.
- GET: an HTTP method for asking the server for something, with data carried in the URL.
- HTTP: the language browsers and servers use to exchange requests and responses.
- POST: an HTTP method for sending data to the server to create or change something.
- Private program: a bug bounty program you can only join by invitation.
- Referer header: a header the browser sends to say which page the request came from.
- Reputation points: a score a bug bounty platform gives for valid reports.
- Swag: free merchandise given as a reward, such as a T-shirt.
- Wish-list: a list of products a user is interested in.