Skip to content

docs(contenttypeparser): new strict content-type validation - #6925

Merged
jsumners merged 9 commits into
fastify:mainfrom
bcomnes:bret/document-content-type-validation
Sep 2, 2026
Merged

jsumners merged 9 commits into
fastify:mainfrom
bcomnes:bret/document-content-type-validation

Conversation

@bcomnes

@bcomnes bcomnes commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Document the request lifecycle boundary introduced by #6414:

  • malformed Content-Type values are rejected before body parser selection
  • string, RegExp, and catch-all parsers cannot recover invalid values
  • an onRequest hook can narrowly canonicalize known external input
  • repair must happen before request.mediaType is accessed and cached
  • broad recovery can undermine parser selection and schema.body.content guarantees

The example intentionally handles one exact malformed value and leaves every unrelated value under Fastify strict validation.

Checklist

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Aug 8, 2026
Comment thread docs/Reference/ContentTypeParser.md Resolved
@jean-michelet
jean-michelet requested a review from jsumners August 9, 2026 14:13
Comment thread docs/Reference/ContentTypeParser.md Resolved
Comment thread docs/Reference/ContentTypeParser.md Resolved
@jsumners

Copy link
Copy Markdown
Member

I will look at this. But it's going to be a couple of days before I can.

@Fdawgs Fdawgs changed the title Document new strict content-type validation docs(contenttypeparser): new strict content-type validation Aug 12, 2026
@bcomnes

bcomnes commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor Author

I will look at this. But it's going to be a couple of days before I can.

Don't yet, need to fix up. (Doing that now)

@jsumners

Copy link
Copy Markdown
Member

I will look at this. But it's going to be a couple of days before I can.

Don't yet, need to fix up. (Doing that now)

Please ping when ready.

@bcomnes

bcomnes commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

I ended up with unexpected travel last week. Will incorporate all open feedback in my open PRs this week.

@bcomnes

bcomnes commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Looking at these again, sorry for the delay.

@bcomnes
bcomnes force-pushed the bret/document-content-type-validation branch from 20d14e3 to 1776bf4 Compare August 27, 2026 23:58
@bcomnes

bcomnes commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@jsumners ok! fixed up let me know what you think. Sorry for the delay.

jsumners
jsumners previously approved these changes Aug 28, 2026

@jsumners jsumners left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I prefer "rewrite" to "repair." Repair has a different connotation to me.

Comment thread docs/Reference/ContentTypeParser.md Resolved
Comment thread docs/Reference/ContentTypeParser.md Resolved
Comment thread docs/Reference/ContentTypeParser.md Resolved
@bcomnes

bcomnes commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Fixed up! Thank you for the review suggestion blocks.

Comment thread docs/Reference/ContentTypeParser.md Resolved
@bcomnes

bcomnes commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Oh crap what did I do need to revert that last thing.

@bcomnes
bcomnes force-pushed the bret/document-content-type-validation branch from 5d2204b to e346e95 Compare August 28, 2026 17:47
@bcomnes

bcomnes commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Fixed.

@bcomnes

bcomnes commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Rewrite the header before accessing request.mediaType,
which parses and caches the current value.

Should fastify actually guard for this? (If mediaType is accessed before rewriting the header in onRequest).

@jsumners

jsumners commented Sep 2, 2026

Copy link
Copy Markdown
Member

Rewrite the header before accessing request.mediaType,
which parses and caches the current value.

Should fastify actually guard for this? (If mediaType is accessed before rewriting the header in onRequest).

🤷‍♂️ Seems like an edge case. But if you feel strongly about it, go for it.

@jsumners
jsumners requested a review from Fdawgs September 2, 2026 11:04

This comment was marked as low quality.

@bcomnes

bcomnes commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Seems like an edge case. But if you feel strongly about it, go for it.

Happy to revisit if its an issue people run into. Thank you for the review!

bcomnes and others added 9 commits September 2, 2026 18:12
Signed-off-by: Bret Comnes <bret@comnes.org>
Signed-off-by: Bret Comnes <bret@comnes.org>
Signed-off-by: Bret Comnes <bret@comnes.org>
Co-authored-by: James Sumners <321201+jsumners@users.noreply.github.com>
Signed-off-by: Bret Comnes <166301+bcomnes@users.noreply.github.com>
Co-authored-by: James Sumners <321201+jsumners@users.noreply.github.com>
Signed-off-by: Bret Comnes <166301+bcomnes@users.noreply.github.com>
@jsumners
jsumners force-pushed the bret/document-content-type-validation branch from e346e95 to 6bc6f67 Compare September 2, 2026 22:12
@jsumners
jsumners merged commit af6e2e4 into fastify:main Sep 2, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants