Skip to content

Commit c34a019

Browse files
committed
fix: use text/plain for callback responses to prevent XSS
1 parent 345bf53 commit c34a019

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/scenarios/server-auth/helpers/oauth-client.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,30 +325,26 @@ export class ConformanceOAuthProvider implements OAuthClientProvider {
325325
const error = url.searchParams.get('error');
326326

327327
if (error) {
328-
res.writeHead(400, { 'Content-Type': 'text/html' });
329-
res.end(
330-
`<html><body><h1>Authorization Error</h1><p>${error}</p></body></html>`
331-
);
328+
res.writeHead(400, { 'Content-Type': 'text/plain' });
329+
res.end(`Authorization Error: ${error}`);
332330
this._stopCallbackServer();
333331
reject(new Error(`Authorization error: ${error}`));
334332
return;
335333
}
336334

337335
if (code) {
338336
this._authCode = code;
339-
res.writeHead(200, { 'Content-Type': 'text/html' });
337+
res.writeHead(200, { 'Content-Type': 'text/plain' });
340338
res.end(
341-
`<html><body><h1>Authorization Successful!</h1><p>You can close this window and return to the terminal.</p></body></html>`
339+
'Authorization successful! You can close this window and return to the terminal.'
342340
);
343341
this._stopCallbackServer();
344342
resolve();
345343
return;
346344
}
347345

348-
res.writeHead(400, { 'Content-Type': 'text/html' });
349-
res.end(
350-
`<html><body><h1>Missing Code</h1><p>No authorization code received.</p></body></html>`
351-
);
346+
res.writeHead(400, { 'Content-Type': 'text/plain' });
347+
res.end('Missing authorization code');
352348
} else {
353349
res.writeHead(404);
354350
res.end('Not found');

0 commit comments

Comments
 (0)