Skip to content

fix(appraisal): require JSON content type on POST /appraise (415) - #672

Open
aladuru001 wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
aladuru001:fix/537-appraisal-json-content-type
Open

aladuru001 wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
aladuru001:fix/537-appraisal-json-content-type

Conversation

@aladuru001

Copy link
Copy Markdown
Contributor

Summary

POST /appraise parsed any body as JSON regardless of Content-Type. It now requires JSON and answers anything else with a stable 415.

  • Missing or non-JSON Content-Type → 415 { "error": "unsupported_media_type", "expected": "application/json" } with Accept-Post: application/json and 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/json is matched exactly and case-insensitively, with optional parameters (application/json; charset=utf-8, quoted charset, extra params). application/jsonp, text/json, application/json-patch+json and application/vnd.api+json are rejected.
  • A charset is 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.
  • Valid JSON with a charset parameter still reaches the payment challenge. Invalid JSON and empty bodies with a JSON content type keep their existing 400.
  • Behaviour change to note: a POST /appraise with no Content-Type previously reached JSON parsing; it is now 415. Every in-repo caller (agent bidder, e2e scripts, tests) already sends application/json. createPaidFetch does not add the header, so API clients must set it (now stated in the README).
  • Documented in services/appraisal-api/README.md.

Closes #537

Supply-chain review

  • No package scripts or dependencies changed. (Only the test script gains the new test file; no dependency or lifecycle script changes.)
  • No .vscode/, workflow, or other editor/config file changes.
  • No lockfile changes.
  • No binary or font asset changes.
  • I confirm no automatic task (such as preinstall/postinstall) was added.
  • I confirm no hidden executable payload was added.
  • Any changed executable or binary was reviewed by a maintainer (none changed).

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 against buildAppraisalServer (415 with Accept-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 existing body-limit.test.ts: 12/12 pass. Run on Windows, Node 20 (repo wants ≥22).

Other tests in this package: quote-guard.test.ts has one failure on an unmodified upstream/main checkout too (paid fetch never produces a payment transaction on drift), and the unfiltered client.test.ts hangs locally there as well; neither touches the server. Please rely on CI for those.

🤖 Generated with Claude Code

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>
@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(high/easy): require JSON content type on appraisal requests

1 participant