Skip to content

Commit acbbadb

Browse files
committed
Ask Claude whether token requests can be JSON.
prompt: In `handleTokenRequest()`, the request is allowed to be JSON or FormData. Does the OAuth spec actually specify both of these as options? Claude "researched" the topic (including attempting to curl the current OAuth 2.1 draft, but apparently curl is blocked by the Claude Code tool "for security reasons"), then said: ``` Based on my research, the current implementation in handleTokenRequest() accepts both JSON and form-urlencoded formats for token requests, but this doesn't comply with the OAuth specifications: 1. RFC 6749 (OAuth 2.0) Section 2.3 specifically states: The client MUST use the "application/x-www-form-urlencoded" format as defined by W3C.HTML 4.01 Specification with a character encoding of UTF-8 in the HTTP request entity-body. 2. The OAuth 2.1 draft maintains this requirement. To strictly follow the OAuth specs, the implementation should only accept application/x-www-form-urlencoded content type for token requests and should return an error for other content types. Would you like me to modify the code to make it strictly compliant with the OAuth specification? ``` prompt: Yes
1 parent 19aa23e commit acbbadb

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

oauth-provider.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,20 @@ class OAuthProviderImpl {
822822
let contentType = request.headers.get('Content-Type') || '';
823823
let body: any = {};
824824

825-
if (contentType.includes('application/json')) {
826-
body = await request.json();
827-
} else {
828-
// Assume application/x-www-form-urlencoded
829-
const formData = await request.formData();
830-
for (const [key, value] of formData.entries()) {
831-
body[key] = value;
832-
}
825+
// According to OAuth 2.0 RFC 6749 Section 2.3, token requests MUST use
826+
// application/x-www-form-urlencoded content type
827+
if (!contentType.includes('application/x-www-form-urlencoded')) {
828+
return createErrorResponse(
829+
'invalid_request',
830+
'Content-Type must be application/x-www-form-urlencoded',
831+
400
832+
);
833+
}
834+
835+
// Process application/x-www-form-urlencoded
836+
const formData = await request.formData();
837+
for (const [key, value] of formData.entries()) {
838+
body[key] = value;
833839
}
834840

835841
// Authenticate client

0 commit comments

Comments
 (0)