Skip to content

Fix duplicated Content-Type header and reject mismatched PATCH ids - #62

Open
jgoclawski wants to merge 2 commits into
masterfrom
general_fixes
Open

jgoclawski wants to merge 2 commits into
masterfrom
general_fixes

Conversation

@jgoclawski

Copy link
Copy Markdown
Member

Summary

Two independent fixes, released ahead of the layered API redesign.

  • Single Content-Type header. JSON:API responses carried two Content-Type headers: Flask's default text/html and application/vnd.api+json. They now carry only the JSON:API one. BaseJsonApiResponse.base_header is replaced by content_type.
  • 409 Conflict on a mismatched PATCH id. The JSON:API specification requires a server to reject a PATCH whose resource id does not match the endpoint. ResourceDetail.patch now returns 409 when the body's data.id, or an id that ends up in the loaded payload (for example through attributes.id), differs from the URL id. Without this, a view that passes the loaded body straight to repository.update(data) updates the object named in the body after any permission check ran on the object named in the URL. A body without an id keeps working as before.

Behaviour changes

  • Clients that send a body id different from the URL id, including one that differs only in letter case, now receive 409 instead of having the URL id silently win.
  • A Content-Type header passed to a JSON:API response is now overridden by the JSON:API one.

Testing

  • New tests for the single header and for the id check: mismatched data.id, mismatched attributes.id with and without a matching data.id, a numeric body id matching a string URL id, a body without id, and a body without data.
  • 142 tests pass, flake8 clean.

🤖 Generated with Claude Code

jgoclawski and others added 2 commits October 17, 2026 23:04
Before that there were 2 headers set,
one default one "text/html".

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Views that pass the loaded body straight to repository.update(data) used
the body's id, so the update could hit a different object than the one
the permission check loaded from the URL. marshmallow-jsonapi lets an
"id" attribute overwrite data.id, so the id is checked both in the raw
body and in the loaded payload.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant