CSRF in generating developer api_key
The API endpoint that regenerates developer API keys lacked CSRF protection, so a malicious page could silently submit a request on behalf of a logged-in developer. This would replace the developer's existing API keys without their knowledge, breaking their application until they updated the keys everywhere.
- Triaged in 36 hours
- Fixed in 24 days
- Paid in 11 days
- Disclosed after 5 months
Hi
At https://dashboard.forttmatic.com when developer tries to generate new api_key for his application, a POST request is sent to https://api.forttmatic.com which doesn't have any tokens to guard against CSRF attacks.
###CSRF POC :
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="https://api.fortmatic.com/v1/dashboard/api_user/keys/regenerate" method="POST" enctype="text/plain">
<input type="hidden" name="{}" value="" />
<input type="submit" value="Generate New Keys" />
</form>
</body>
</html>
On submitting the above request, a new set of keys would be generated which destroys the current api_key set without the knowledge of developer.
Impact
It doesn't have a great security impact other than that this would make the developer's app unusable because he would have to change the api_keys everywhere on his code to make the application working again. This could be done any number of times. Everytime the developer has attacker's site opened in his browser keys would be regenerated leading to developer being left frustrated as to why his api_keys keep on changing even when he didn't ask for it and the pain to replace old pair of keys with the new one! :)
Context
Magic (Fortmatic) provides a developer dashboard at https://dashboard.forttmatic.com where developers manage their applications. One of the actions available there is generating a new API key pair for an application. When the developer triggers that action, the dashboard sends a POST request to the API host https://api.fortmatic.com, specifically to the key regeneration endpoint. The report is about that endpoint accepting the request without any CSRF protection.
Setup
Finding it
While looking at the key generation flow, the researcher noticed that the POST request sent to https://api.forttmatic.com carries no token that would guard it against cross-site request forgery. The report says the request carries no tokens to guard against CSRF attacks. That made the endpoint a candidate for a CSRF attack, and the researcher built a proof of concept to confirm it.
Exploitation
Step 1: Host a page that submits the regeneration request
The researcher wrote a minimal HTML page that, when opened in a browser, automatically submits a form to the key regeneration endpoint:
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="https://api.fortmatic.com/v1/dashboard/api_user/keys/regenerate" method="POST" enctype="text/plain">
<input type="hidden" name="{}" value="" />
<input type="submit" value="Generate New Keys" />
</form>
</body>
</html>
The important parts:
- The form
actionpoints athttps://api.fortmatic.com/v1/dashboard/api_user/keys/regenerate, the endpoint the dashboard itself uses to rotate keys. - The method is
POST, matching the legitimate request. - The hidden field is named
{}, which is the HTML entity encoding of{}.
Step 2: The developer opens the page
Because the endpoint has no CSRF token check, the request is processed as if the developer had clicked the button in the dashboard.
Step 3: The keys are rotated
On submitting the request, a new set of keys is generated. The current API key set is destroyed in the process, and this happens without the developer's knowledge.
Root cause
The key regeneration endpoint on api.fortmatic.com performs a state-changing action based solely on the session, with no anti-CSRF token in the request. The report states plainly that the request "doesn't have any tokens to guard against CSRF attacks".
Impact
The researcher is explicit that the security impact is limited: the attack does not leak data or grant access. What it does is make the developer's application unusable, because the API keys embedded throughout the developer's code stop working and must be replaced everywhere for the application to function again. The attack can be repeated any number of times: every time the developer has the attacker's site open in the browser, the keys are regenerated. The practical result is a developer left frustrated, wondering why the keys keep changing when they never asked for it, plus the work of swapping the old pair for the new one.
Fix
The report does not describe a fix or a change made by the program. The obvious remedy, given the root cause, is to require an anti-CSRF token on the key regeneration endpoint (and on any other state-changing endpoint on the same host), and to reject requests whose Origin or Referer does not match the dashboard. The report does not state which of these was implemented.
Variants to test
- Other state-changing endpoints on the same API host: try the same
text/plainform trick against endpoints that create, delete or rotate resources. A positive result is a change in state visible in the account after the victim loads the page. - Endpoints that accept JSON bodies: if the server parses
text/plainbodies as JSON (the{}field name trick), the same page shape may work. A positive result is the server acting on the request despite the content type. - Endpoints protected only by
Origin/Refererchecks: test whether the check is present and whether it can be bypassed (for example, by a page whose URL contains the expected origin as a substring). A positive result is the request being processed from an unrelated origin. - Key rotation and similar destructive actions in other dashboards: the same pattern applies wherever a single click rotates credentials. A positive result is the victim's credentials changing without their action.
Hunting notes
This kind of bug tends to hide in dashboard actions that change state but are not obviously sensitive: key rotation, webhook URL changes, email changes, and similar settings. During recon, watch for POST requests from the dashboard to a separate API host, especially ones whose bodies are JSON or empty, and check whether any anti-CSRF token is present in the request. If the endpoint accepts text/plain or application/x-www-form-urlencoded bodies and does not check Origin, a simple auto-submitting form is enough.
What happened, in plain words
Magic (also called Fortmatic) runs a website called a developer dashboard at https://dashboard.forttmatic.com. A dashboard is a private control panel: you log in, and then you can see and change the things that belong to you. In this case, developers use it to manage their applications, and one of the things they can do there is generate a new pair of API keys for an application.
An API key is a long secret string that identifies an application to a service. Think of it like the key to a flat: anyone holding it can get in, and if you change the lock, every copy of the old key stops working. Developers copy their API keys into their own code, so the key is spread around in many places.
The problem the researcher found is that the action of generating new keys could be triggered by any website, not just the dashboard. A malicious page could make a logged-in developer's browser send the key-regeneration request, and the server would happily carry it out. The developer's old keys would be destroyed and replaced with new ones they never asked for, breaking their application until they updated the keys everywhere.
This class of bug is called Cross-Site Request Forgery, or CSRF. The idea is simple: your browser automatically attaches your login information (cookies) to requests sent to a site you are logged into. If another site can make your browser send a request to that site, the request arrives looking exactly as if you had made it yourself. The defence is to include a secret, unpredictable value (an anti-CSRF token) in each state-changing request, something a third-party page cannot know. The report says this endpoint had no such token.
Context
Magic (Fortmatic) provides a developer dashboard at https://dashboard.forttmatic.com where developers manage their applications. One of the actions available there is generating a new API key pair for an application. When the developer triggers that action, the dashboard sends a POST request to the API host https://api.fortmatic.com, specifically to the key regeneration endpoint. The report is about that endpoint accepting the request without any CSRF protection.
A few terms in that paragraph are worth unpacking for a newcomer:
- Dashboard: the logged-in web interface where you manage your account and settings.
- API host: a separate server that the dashboard talks to behind the scenes. The dashboard is the shop front; the API host is the back office where the actual work happens.
- POST request: one of the ways a browser talks to a server. A GET request is like asking to read a page; a POST request is like submitting a form, and it is normally used when something should change on the server.
- Endpoint: a specific address on a server that does one particular job, for example the address that regenerates keys.
- CSRF protection: a check that makes sure a state-changing request really came from the site's own pages and not from somewhere else.
Setup
A session here means the period during which you are logged in. When you log in, the server gives your browser a cookie, a small piece of data stored by the browser, which it sends back on every later request to that site so the server knows who you are. As long as that cookie is valid, you are "logged in" from the server's point of view, even if you are looking at a completely different website in another tab.
A proof of concept (PoC) is a small, safe demonstration that shows a bug is real. Here it is a single HTML file, the same kind of file that makes up any web page, which the researcher opens in a browser to prove the attack works.
Finding it
While looking at the key generation flow, the researcher noticed that the POST request sent to https://api.forttmatic.com carries no token that would guard it against cross-site request forgery. The report says the request carries no tokens to guard against CSRF attacks. That made the endpoint a candidate for a CSRF attack, and the researcher built a proof of concept to confirm it.
"Ambient session" means the login is implied by the cookie the browser sends automatically, rather than by something the request itself proves. If the only thing that authorises a request is a cookie, then anyone who can make your browser send that request can also trigger the action. A CSRF token fixes this because it is a value stored in the page and sent in the request, and an attacker's page has no way to read it.
Exploitation
Step 1: Host a page that submits the regeneration request
The researcher wrote a minimal HTML page that, when opened in a browser, automatically submits a form to the key regeneration endpoint:
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="https://api.fortmatic.com/v1/dashboard/api_user/keys/regenerate" method="POST" enctype="text/plain">
<input type="hidden" name="{}" value="" />
<input type="submit" value="Generate New Keys" />
</form>
</body>
</html>
Line by line, in plain words:
<html>and<body>are the outer wrappers of any web page. Everything visible or active on the page sits inside them.<script>history.pushState('', '', '/')</script>runs a tiny piece of JavaScript, the programming language browsers understand.history.pushStatechanges the address shown in the browser's address bar without loading a new page.<form ...>starts a form, the same mechanism used by any login box or search box. A form collects values and sends them to a server.action="https://api.fortmatic.com/v1/dashboard/api_user/keys/regenerate"says where the form is sent: the exact endpoint the dashboard itself uses to rotate keys. This is the heart of the attack, because the browser will send the request to that server, not to the attacker's server.method="POST"says how it is sent, matching the legitimate request the dashboard makes.enctype="text/plain"controls how the form data is formatted. A preflight is an extra permission-check request the browser sends before certain kinds of cross-origin requests; simple form submissions skip it, which is exactly what the attacker wants.<input type="hidden" name="{}" value="" />is a form field the visitor never sees. Its name is written as{}, which is the HTML entity encoding of{}. Browsers decode entities when they read the page, so the server receives a field literally named{}. JSON is a text format for structured data that commonly uses curly braces;<input type="submit" value="Generate New Keys" />is the button.
Step 2: The developer opens the page
Because the endpoint has no CSRF token check, the request is processed as if the developer had clicked the button in the dashboard.
This is the key moment to understand. The browser does not ask the developer for permission, and it does not care that the page came from a different site. The server sees a valid session and a request in the expected shape, so it acts.
Step 3: The keys are rotated
On submitting the request, a new set of keys is generated. The current API key set is destroyed in the process, and this happens without the developer's knowledge.
"Rotated" simply means replaced with fresh ones. The old keys are not kept alongside the new ones; they are gone. Any application still using the old keys will start failing, because the service no longer recognises them.
Root cause
The key regeneration endpoint on api.fortmatic.com performs a state-changing action based solely on the session, with no anti-CSRF token in the request. The report states plainly that the request "doesn't have any tokens to guard against CSRF attacks".
Two more terms from that paragraph:
- State-changing action: anything that alters data on the server, such as creating, deleting or replacing something. Reading a page is not state-changing; regenerating keys is.
OriginandReferer: HTTP headers, pieces of information the browser attaches to requests, that say which site the request came from. A server can refuse requests whose origin is not its own dashboard.
Impact
The researcher is explicit that the security impact is limited: the attack does not leak data or grant access. What it does is make the developer's application unusable, because the API keys embedded throughout the developer's code stop working and must be replaced everywhere for the application to function again. The attack can be repeated any number of times: every time the developer has the attacker's site open in the browser, the keys are regenerated. The practical result is a developer left frustrated, wondering why the keys keep changing when they never asked for it, plus the work of swapping the old pair for the new one.
In security language, this is an availability problem rather than a confidentiality problem. Nothing secret is stolen and no one gains access they should not have. Instead, the legitimate owner is locked out of their own working setup until they do the repair work. The report's own framing is that the impact is not great in security terms, but it is real and repeatable.
Fix
The report does not describe a fix or a change made by the program. The obvious remedy, given the root cause, is to require an anti-CSRF token on the key regeneration endpoint (and on any other state-changing endpoint on the same host), and to reject requests whose Origin or Referer does not match the dashboard. The report does not state which of these was implemented.
Variants to test
- Other state-changing endpoints on the same API host: try the same
text/plainform trick against endpoints that create, delete or rotate resources. A positive result is a change in state visible in the account after the victim loads the page. - Endpoints that accept JSON bodies: if the server parses
text/plainbodies as JSON (the{}field name trick), the same page shape may work. A positive result is the server acting on the request despite the content type. - Endpoints protected only by
Origin/Refererchecks: test whether the check is present and whether it can be bypassed (for example, by a page whose URL contains the expected origin as a substring). A positive result is the request being processed from an unrelated origin. - Key rotation and similar destructive actions in other dashboards: the same pattern applies wherever a single click rotates credentials. A positive result is the victim's credentials changing without their action.
Hunting notes
This kind of bug tends to hide in dashboard actions that change state but are not obviously sensitive: key rotation, webhook URL changes, email changes, and similar settings. A webhook is a URL that a service calls automatically when something happens, so changing it can redirect data elsewhere. During recon, watch for POST requests from the dashboard to a separate API host, especially ones whose bodies are JSON or empty, and check whether any anti-CSRF token is present in the request. If the endpoint accepts text/plain or application/x-www-form-urlencoded bodies and does not check Origin, a simple auto-submitting form is enough.
Glossary
- API: a way for one piece of software to talk to another, usually over the web, by sending requests to specific addresses.
- API key: a secret string that identifies an application to a service, like a key to a lock.
- API host: the server that handles the API requests, separate from the website you look at.
- Availability: whether a system keeps working for its legitimate users; an availability attack breaks that without stealing anything.
- Cookie: a small piece of data a site stores in your browser and sends back on later requests, commonly used to keep you logged in.
- CORS preflight: an extra permission-check request a browser sends before certain cross-origin requests; simple form submissions skip it.
- CSRF (Cross-Site Request Forgery): tricking a logged-in user's browser into sending a state-changing request to a site they are logged into.
- CSRF token: a secret, unpredictable value included in a request to prove it came from the site's own pages.
- Dashboard: a logged-in web control panel for managing an account or application.
- Endpoint: a specific address on a server that performs one particular job.
- Form: the part of a web page that collects values and sends them to a server.
- GET request: a request that asks to read something, without changing it.
- HTML: the language web pages are written in.
- HTML entity: a code such as
{that stands for a character, here{. - HTTP header: extra information attached to a request or response, such as where the request came from.
- JavaScript: the programming language browsers run inside web pages.
- JSON: a text format for structured data, commonly using curly braces.
- Origin: an HTTP header telling the server which site a request came from.
- POST request: a request that submits data and is normally used when something should change on the server.
- Proof of concept (PoC): a small demonstration that proves a bug is real.
- Referer: an HTTP header telling the server the address of the page that made the request.
- Rotation: replacing a credential, such as a key, with a fresh one and invalidating the old one.
- Session: the period during which you are logged in, tracked by a cookie.
- Webhook: a URL a service calls automatically when an event happens.
text/plain: a content type meaning plain text, used here to send a simple form submission that skips the preflight.