Repository navigation
fix(appraisal): require JSON content type on POST /appraise (415) - #672
Open
aladuru001 wants to merge 1 commit into
Open
aladuru001 wants to merge 1 commit into
aladuru001 wants to merge 1 commit into
Conversation
POST /appraise parsed any body as JSON regardless of Content-Type.
Return a stable 415 (`{ error: "unsupported_media_type", expected:
"application/json" }` plus `Accept-Post`) for a missing or non-JSON
Content-Type, before the body is read and before any payment quote is
built. `application/json` is matched exactly (case-insensitive) with
optional parameters; a charset is accepted only when it is UTF-8, since
the body is decoded as UTF-8. Valid JSON with a charset parameter still
reaches the payment challenge, and invalid/empty bodies keep their 400.
Closes Sub-Rosa-Issue#537
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@aladuru001 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /appraiseparsed any body as JSON regardless ofContent-Type. It now requires JSON and answers anything else with a stable 415.Content-Type→415 { "error": "unsupported_media_type", "expected": "application/json" }withAccept-Post: application/jsonand the existing no-store/nosniff headers. The check runs before the body is read and before any 402 quote is built, so an unsupported request is never offered a payment.application/jsonis matched exactly and case-insensitively, with optional parameters (application/json; charset=utf-8, quoted charset, extra params).application/jsonp,text/json,application/json-patch+jsonandapplication/vnd.api+jsonare rejected.charsetis accepted only when it is UTF-8 (utf-8/utf8) because the body is decoded as UTF-8; another charset would be silently mis-decoded, so it gets 415.POST /appraisewith noContent-Typepreviously reached JSON parsing; it is now 415. Every in-repo caller (agentbidder, e2e scripts, tests) already sendsapplication/json.createPaidFetchdoes not add the header, so API clients must set it (now stated in the README).services/appraisal-api/README.md.Closes #537
Supply-chain review
testscript gains the new test file; no dependency or lifecycle script changes.).vscode/, workflow, or other editor/config file changes.preinstall/postinstall) was added.Testing
src/content-type.test.ts(new, 8 tests): accepted and rejected header matrix, non-UTF-8 charsets, the stable 415 body, and end-to-end againstbuildAppraisalServer(415 withAccept-Post, no payment header; empty body + bad type is 415; valid JSON with and without charset reaches 402; bad/empty JSON body keeps 400). With the existingbody-limit.test.ts: 12/12 pass. Run on Windows, Node 20 (repo wants ≥22).Other tests in this package:
quote-guard.test.tshas one failure on an unmodifiedupstream/maincheckout too (paid fetch never produces a payment transaction on drift), and the unfilteredclient.test.tshangs locally there as well; neither touches the server. Please rely on CI for those.🤖 Generated with Claude Code