Skip to content
CSRF Disclosed report Intermediate

CSRF in all API endpoints when authenticated using HTTP Authentication

API endpoints accepted form-encoded POST requests without CSRF tokens when the user was authenticated via HTTP Basic Auth, allowing an attacker to force a merchant to perform actions like creating products or webhooks. The program noted this was likely not exploitable because saving Basic Auth credentials would break normal web navigation, but fixed it anyway.

Mahmoud Gamal Follow

Originally disclosed on HackerOne

  • Triaged in 32 days
  • Fixed in 2 months
  • Paid in 3 months
  • Disclosed after 3 months

Summary by the program

This issue would have allowed to force a merchant to perform authenticated actions via Shopify's API if this merchant had saved their own API credentials in their browser. While this situation was likely not exploitable (saving basic auth credentials would prevent normal web navigation since API authentication is checked before session authentication) we opted for fixing this issue nonetheless. The fix was not trivial since we use the same domain for both the API and web access, so we ended up denying any requests authenticated with Basic Auth that also provide any http cookies.

The report

#Description: Short: I have found a CSRF vulnerability in all API endpoints /admin/[any_api_endpoint]/ if the current user has authenticated using HTTP authentication.

Details: When a user generates API credentials for a private application in his shop he will be given API key and password that he can use to access his shop resources, moreover shopify provides an HTTP authentication URL to the user as an example URL. ████████

If the user is authenticated through HTTP authentication , the browser will automatically send the credentials in the Authroization header with each request so the user will still be authenticated without need to submit the username and password each time.

I have found that if a user has authenticated through HTTP authentication (opened the example URL that shopify provided him when he created the private application) , all the API endpoints will be vulnerable to CSRF. #Steps to reproduce:

  1. Login to your shopify account
  2. Create a private application then open the authentication example URL in a new browser.
  3. for testing , submit the following form through the browser in which you opened the example link:
<form action="https://[shop].myshopify.com/admin/products.json" method=post>
<input name="product[title]" value="API CSRF TEST">
<input name="product[vendor]" value="test">
<input name="product[body_html]" value="<h1>API CSRF TEST [Can be stored XSS for admins]</h1>">
 <input name="product[product_type]" value="test">
<input type=submit>
</form>

4- Go to [shop].myshopify.com/admin/products and you'll see the product.

All the API endpoints are vulnerable , even the endpoints that only accept (PUT , PATCH or DELETE) , you can submit requests with these methods using _method parameter. #What is the problem here? The vulnerability exists because API endpoints accept data submitted with content-type: application/x-www-form-urlencoded without any validation for the authenticity token if the user is authenticated through HTTP authentication. #Impact: Through this vulnerability an attacker can do malicious actions through the victim's session which includes: creating a webhook that pings the attacker's server for all events happening on the victim's shop, fulfilling orders , creating a transaction ,editing themes ..etc (All possible actions done through the API).

Thanks and happy new year :)

The original report as published on HackerOne, by zombiehelp54. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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. 5 min read.

Context

Shopify merchants can create private applications inside their shop. When they do, Shopify issues an API key and password, and it also shows the merchant an example HTTP authentication URL that embeds those credentials. Opening that URL authenticates the browser against the API using HTTP Basic Auth, and from then on the browser automatically attaches the credentials in the Authorization header to every request for that origin, so the merchant does not have to type the username and password again.

The API lives under /admin/[any_api_endpoint]/ on the same [shop].myshopify.com domain as the normal admin web interface. The report is about what happens to those API endpoints when the browser is already holding Basic Auth credentials for that domain.

Setup

To reproduce, the researcher needed:

  1. A Shopify account with a shop.
  2. A private application created in that shop, which yields the API key and password and the example authentication URL.
  3. A browser in which the example authentication URL has been opened, so the browser stores and replays the Basic Auth credentials.

No special tooling is required: the proof of concept is a plain HTML form submitted from the browser that holds the credentials.

Finding it

The researcher's observation was that once a user has authenticated through HTTP authentication, every API endpoint becomes reachable with a cross-site request. The browser sends the Authorization header automatically on each request, so the user stays authenticated without resubmitting the username and password. The API endpoints accept data submitted with content-type: application/x-www-form-urlencoded and, in this state, perform no validation of the authenticity token.

The report notes that Shopify provides the HTTP authentication URL to the user as an example URL when the private application is created. The report shows the example URL as Shopify presents it when the private application is created.

Exploitation

Step 1: Log in to the Shopify account

Start from a normal logged-in merchant account.

Step 2: Create a private application and open the authentication example URL

Create a private application, then open the authentication example URL that Shopify shows, in a new browser. This is the precondition that makes the rest work: the browser now holds the API credentials and will attach them to subsequent requests to the shop's domain.

Step 3: Submit a form from that browser

For testing, submit the following form through the browser in which the example link was opened:

HTML
<form action="https://[shop].myshopify.com/admin/products.json" method=post>
<input name="product[title]" value="API CSRF TEST">
<input name="product[vendor]" value="test">
<input name="product[body_html]" value="<h1>API CSRF TEST [Can be stored XSS for admins]</h1>">
 <input name="product[product_type]" value="test">
<input type=submit>
</form>

The form posts to the products API endpoint on the shop's domain. The fields are ordinary product attributes: title, vendor, body HTML and product type. Because the browser already holds the Basic Auth credentials for that origin, it adds the Authorization header to the form submission, and the API treats the request as authenticated. The body_html value in the test payload carries a heading, and the payload text itself notes it could be stored XSS for admins.

Step 4: Check the result

Go to [shop].myshopify.com/admin/products and the product created by the form is there. The cross-site form submission produced a real product in the shop.

Beyond POST

All API endpoints are affected, including those that only accept PUT, PATCH or DELETE. Those methods can be reached from a form submission by using the _method parameter.

Root cause

The API endpoints accept data submitted with content-type: application/x-www-form-urlencoded without any validation of the authenticity token when the user is authenticated through HTTP authentication. The CSRF defence that normally protects state-changing requests, the authenticity token check, is not applied on this path, so a request forged by another site is accepted as long as the browser supplies the Basic Auth credentials.

Shopify's own summary explains why the fix was awkward: the same domain serves both the API and the web interface. The program also assessed the practical exposure. The issue would have allowed forcing a merchant to perform authenticated actions via the API if that merchant had saved their own API credentials in their browser. The program considered this situation likely not exploitable, because saving Basic Auth credentials would prevent normal web navigation, since API authentication is checked before session authentication. The program opted to fix the issue regardless.

Impact

Through this vulnerability an attacker can perform malicious actions through the victim's session. The report lists, among the possible actions:

  • creating a webhook that pings the attacker's server for all events happening on the victim's shop;
  • fulfilling orders;
  • creating a transaction;
  • editing themes;
  • in general, all possible actions done through the API.

The condition is that the victim has authenticated through HTTP authentication, that is, has opened the example URL and thereby stored the API credentials in the browser. The program's summary adds the caveat that this was likely not exploitable in practice, because saving Basic Auth credentials would break normal web navigation on the same domain.

Fix

The program opted to fix the issue. It describes the fix as not trivial, because the same domain is used for both the API and web access. The chosen approach was to deny any requests authenticated with Basic Auth that also provide any HTTP cookies.

Variants to test

  • Basic Auth plus form-encoded body on API endpoints. On any target that offers HTTP Basic Auth for an API on the same origin as the web application, submit a cross-site form with content-type: application/x-www-form-urlencoded to a state-changing endpoint. A positive result is a resource created or modified without any authenticity token.
  • Method override through _method. Where a framework honours a _method parameter, send a form POST carrying _method=PUT, _method=PATCH or _method=DELETE to endpoints that only accept those verbs. A positive result is the update or deletion being applied.
  • Mixed authentication on one origin. Look for setups where API authentication is evaluated before session authentication on a shared domain. A positive result is an API request that succeeds on Basic Auth credentials while the browser also sends session cookies, which is exactly the combination Shopify chose to deny.
  • Stored content in created objects. When a forged request can create content with HTML fields, as with body_html here, check whether that content is rendered to administrators without sanitisation. A positive result is script execution in an admin's browser.

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. 12 min read.

What happened, in plain words

Shopify is a platform that lets people run online shops. Each shop lives at an address like [shop].myshopify.com. Behind that address there is a normal web interface that a shop owner uses in a browser, and there is also an API: a second way to talk to the same shop, meant for programs rather than people. Think of the web interface as the shop's front door with a counter and staff, and the API as a service hatch at the back where a delivery robot can drop off or pick up boxes without anyone clicking buttons.

To use the API, a shop owner creates something called a private application inside their shop. Shopify then hands them two pieces of information: an API key (a username) and a password. Together these are the shop's API credentials. Shopify also shows the owner an example URL that already contains those credentials, so the owner can try the API quickly.

When a browser opens a URL that contains a username and password in this way, it uses a mechanism called HTTP Basic Auth. The browser remembers the credentials and, from then on, quietly attaches them to every request it sends to that same site, so the owner never has to type them again. This is convenient, and it is also the setup that made the bug possible.

The bug is a CSRF (Cross-Site Request Forgery). In plain terms: a website you visit can make your browser send a request to a different website, and your browser will attach whatever credentials it holds for that other website. You do not click anything on the target site; the attacker's page does the clicking for you. The defence that sites normally use against this is a secret authenticity token: a value that only the real site's pages know, which the browser must include with any request that changes something. If the token is missing or wrong, the request is rejected.

In this report, the researcher found that Shopify's API endpoints did not check that token when the browser was authenticated with Basic Auth. So a page on another site could submit a form to the shop's API, the browser would add the stored credentials automatically, and the API would carry out the action as if the shop owner had asked for it. The researcher demonstrated this by creating a product in the shop from a plain HTML form.

Shopify's own summary says the issue would have let someone force a merchant to perform authenticated actions through the API, but only if that merchant had saved their own API credentials in their browser. The program judged this likely not exploitable in practice, because saving Basic Auth credentials would get in the way of normal browsing on the same site: API authentication is checked before session authentication. Even so, they fixed it. The fix was not simple, because the API and the web interface share one domain. The chosen approach was to deny any request that is authenticated with Basic Auth and that also carries any HTTP cookies.

The pieces you need to know

Before walking through the steps, here are the concepts that appear in the report, explained from zero.

  • API: a way for software to talk to a service. Instead of a page with buttons, you send a request to an address (an endpoint) and get data back. Shopify's API lives under paths like /admin/[any_api_endpoint]/.
  • Endpoint: one specific address on a server that does one specific job. /admin/products.json is the endpoint for products.
  • HTTP Basic Auth: a simple login method where the browser sends a username and password with every request, encoded in a header called Authorization. Once the browser has them, it replays them automatically.
  • Header: extra information attached to a request, separate from the body. Think of it as the label on a parcel, while the body is what is inside.
  • Cookie: a small piece of data a site stores in your browser so it can recognise you on later visits. A session cookie is what keeps you logged in to the web interface.
  • CSRF (Cross-Site Request Forgery): tricking a logged-in browser into sending a request to a site it is logged in to, from a page on a different site.
  • Authenticity token: a secret value embedded in a site's own forms. The server checks it to confirm the request really came from its own pages and not from somewhere else.
  • content-type: application/x-www-form-urlencoded: the format a normal HTML form uses when it submits. The fields are sent as name=value pairs.
  • _method parameter: a convention where a form, which can only send GET or POST, includes a field named _method to tell the server to treat the request as PUT, PATCH or DELETE instead.
  • PUT, PATCH, DELETE: HTTP methods. POST usually creates, PUT and PATCH usually update, DELETE removes. A plain HTML form can only send GET and POST, which is why _method matters.
  • Webhook: a message a service sends automatically to another address when something happens. If an attacker can create a webhook, they can have every event in the shop forwarded to their own server.
  • Stored XSS: when a site saves content containing a script and later shows it to someone, the script runs in that person's browser. The report flags the body_html field as a possible place for this.

Setting up the test

To reproduce the issue, the researcher needed three things:

  1. A Shopify account with a shop.
  2. A private application created in that shop. Creating it produces the API key and password, and Shopify shows the example authentication URL.
  3. A browser in which that example authentication URL has been opened, so the browser stores the Basic Auth credentials and replays them on later requests.

No special tools are involved. The proof of concept is an ordinary HTML form, the same kind of thing any web page can contain, submitted from the browser that holds the credentials.

Finding it

The researcher's observation was simple: once a user has authenticated through HTTP authentication, every API endpoint becomes reachable with a request coming from another site. The browser sends the Authorization header automatically on each request, so the user stays authenticated without retyping the username and password. The API endpoints accept data sent as content-type: application/x-www-form-urlencoded and, in this state, do not validate the authenticity token.

The report notes that Shopify provides the HTTP authentication URL to the user as an example URL when the private application is created. The report shows the example URL as Shopify presents it when the private application is created.

Exploitation, step by step

Step 1: Log in to the Shopify account

Start from a normal merchant account that is logged in. This gives you a shop to work with and the ability to create a private application.

Step 2: Create a private application and open the authentication example URL

Create a private application, then open the authentication example URL that Shopify shows, in a new browser. This step is the precondition for everything that follows: after opening that URL, the browser holds the API credentials and will attach them to later requests to the shop's domain. Without this, the forged form would arrive unauthenticated and be rejected.

Step 3: Submit a form from that browser

For testing, submit the following form through the browser in which the example link was opened:

HTML
<form action="https://[shop].myshopify.com/admin/products.json" method=post>
<input name="product[title]" value="API CSRF TEST">
<input name="product[vendor]" value="test">
<input name="product[body_html]" value="<h1>API CSRF TEST [Can be stored XSS for admins]</h1>">
 <input name="product[product_type]" value="test">
<input type=submit>
</form>

Line by line:

  • <form action="https://[shop].myshopify.com/admin/products.json" method=post> opens the form and says where it goes. The action is the products API endpoint on the shop's own domain, and method=post means the browser will send the fields as a POST request. This is the request that, in a real attack, would be placed on an attacker's page instead of being typed by the victim.
  • <input name="product[title]" value="API CSRF TEST"> is one field of the new product: its title. The odd-looking name product[title] is how the API is told that this value belongs to the title attribute of a product.
  • <input name="product[vendor]" value="test"> sets the product's vendor to test.
  • <input name="product[body_html]" value="<h1>API CSRF TEST [Can be stored XSS for admins]</h1>"> sets the product description. The value contains an HTML heading, and the researcher notes in the text that this could be stored XSS for admins who view the product.
  • <input name="product[product_type]" value="test"> sets the product type to test.
  • <input type=submit> is the button that sends the form.

The form posts to the products API endpoint on the shop's domain. The fields are ordinary product attributes: title, vendor, body HTML and product type. Because the browser already holds the Basic Auth credentials for that origin, it adds the Authorization header to the form submission, and the API treats the request as authenticated. No authenticity token is included, and none is required on this path.

Step 4: Check the result

Go to [shop].myshopify.com/admin/products and the product created by the form is there. A form submitted from a page that is not the shop's own interface produced a real product in the shop. That is the proof: the request was forged, yet it was accepted.

Beyond POST

All API endpoints are affected, including those that only accept PUT, PATCH or DELETE. A plain HTML form cannot send those methods, but it can send a POST containing a _method field, and the server will treat the request as the method named in that field. So the same trick reaches update and delete operations too.

Why it worked

The API endpoints accept data submitted with content-type: application/x-www-form-urlencoded without any validation of the authenticity token when the user is authenticated through HTTP authentication. The CSRF defence that normally protects requests that change things, the authenticity token check, is simply not applied on this path. A request forged by another site is therefore accepted as long as the browser supplies the Basic Auth credentials.

Shopify's summary explains why the fix was awkward: the same domain serves both the API and the web interface. The program also weighed the practical exposure. The issue would have allowed forcing a merchant to perform authenticated actions through the API if that merchant had saved their own API credentials in their browser. The program considered this likely not exploitable, because saving Basic Auth credentials would prevent normal web navigation, since API authentication is checked before session authentication. The program opted to fix the issue regardless.

What an attacker could have done

Through this vulnerability an attacker can perform malicious actions through the victim's session. The report lists, among the possible actions:

  • creating a webhook that pings the attacker's server for all events happening on the victim's shop;
  • fulfilling orders;
  • creating a transaction;
  • editing themes;
  • in general, all possible actions done through the API.

The condition is that the victim has authenticated through HTTP authentication, meaning they opened the example URL and thereby stored the API credentials in the browser. The program's summary adds the caveat that this was likely not exploitable in practice, because saving Basic Auth credentials would break normal web navigation on the same domain.

The fix

The program opted to fix the issue. It describes the fix as not trivial, because the same domain is used for both the API and web access. The chosen approach was to deny any request authenticated with Basic Auth that also provides any HTTP cookies. In other words: if a request arrives carrying both the API credentials and the browser's session cookies, it is refused.

Variants worth testing elsewhere

The same pattern can appear on other sites. These are the variations the report's reasoning suggests checking:

  • Basic Auth plus form-encoded body on API endpoints. On any target that offers HTTP Basic Auth for an API on the same origin as the web application, submit a cross-site form with content-type: application/x-www-form-urlencoded to an endpoint that changes something. A positive result is a resource created or modified without any authenticity token.
  • Method override through _method. Where a framework honours a _method parameter, send a form POST carrying _method=PUT, _method=PATCH or _method=DELETE to endpoints that only accept those verbs. A positive result is the update or deletion being applied.
  • Mixed authentication on one origin. Look for setups where API authentication is evaluated before session authentication on a shared domain. A positive result is an API request that succeeds on Basic Auth credentials while the browser also sends session cookies, which is exactly the combination Shopify chose to deny.
  • Stored content in created objects. When a forged request can create content with HTML fields, as with body_html here, check whether that content is rendered to administrators without sanitisation. A positive result is script execution in an admin's browser.

Glossary

  • API: a way for software to talk to a service by sending requests to specific addresses, instead of a person clicking through pages.
  • Endpoint: one specific address on a server that performs one specific job, such as creating a product.
  • HTTP Basic Auth: a login method where the browser sends a username and password with every request, encoded in the Authorization header, and replays them automatically once entered.
  • Authorization header: the part of a request that carries the credentials for Basic Auth.
  • Header: extra information attached to a request or response, separate from the body.
  • Cookie: a small piece of data a site stores in the browser so it can recognise the visitor later.
  • Session cookie: the cookie that keeps a user logged in to the web interface.
  • CSRF (Cross-Site Request Forgery): making a logged-in browser send a request to a site it is logged in to, from a page on a different site, without the user intending it.
  • Authenticity token: a secret value placed in a site's own forms and checked by the server to confirm the request came from the site itself.
  • content-type: application/x-www-form-urlencoded: the format a normal HTML form uses, sending fields as name=value pairs.
  • POST: the HTTP method a form uses to send data to a server, typically to create something.
  • PUT, PATCH, DELETE: HTTP methods for updating and removing resources; a plain HTML form cannot send them directly.
  • _method parameter: a form field that tells the server to treat a POST as another method such as PUT, PATCH or DELETE.
  • Webhook: an automatic message a service sends to another address when an event happens.
  • Stored XSS: saving content that contains a script, which then runs in the browser of anyone who views it.
  • Private application: an application created inside a Shopify shop that comes with its own API key and password.
  • API key: the username part of the API credentials.
  • Origin: the combination of scheme, host and port that a browser uses to decide which credentials and cookies belong to which site.

More by Mahmoud Gamal

View all

32 more disclosed reports, best first.

More from Shopify

View all

The newest disclosed reports for this program.

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.