Skip to content

fix: remove format placeholder from FST_ERR_CTP_INVALID_MEDIA_TYPE message#6528

Merged
mcollina merged 1 commit intofastify:mainfrom
super-mcgin:fix/ctp-invalid-media-type-message
Feb 28, 2026
Merged

fix: remove format placeholder from FST_ERR_CTP_INVALID_MEDIA_TYPE message#6528
mcollina merged 1 commit intofastify:mainfrom
super-mcgin:fix/ctp-invalid-media-type-message

Conversation

@super-mcgin
Copy link
Contributor

@super-mcgin super-mcgin commented Feb 23, 2026

Summary

  • The error message template 'Unsupported Media Type: %s' produced the literal string %s when instantiated without arguments (as in lib/handle-request.js).
  • Rather than reflecting the raw content-type header back to the client (which would expose unsanitized user input in error responses and logs), the template is changed to the static message 'Unsupported Media Type'.
  • Both callsites (lib/handle-request.js and lib/content-type-parser.js) now instantiate the error with no arguments.

Breaking change

This is a minor breaking change for consumers that match on the exact error.message string (previously 'Unsupported Media Type: <content-type>', now 'Unsupported Media Type'). The error code FST_ERR_CTP_INVALID_MEDIA_TYPE and HTTP status 415 are unchanged and should be used for programmatic error handling instead.

Test plan

  • Added test that sends an invalid content-type header and asserts the error message is 'Unsupported Media Type' (no %s placeholder)
  • Updated existing error unit test to expect the new message
  • All tests pass (2164 pass, 0 fail)
  • Lint passes

🤖 Generated with Claude Code

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

…ssage

The error message template 'Unsupported Media Type: %s' produced the
literal string '%s' when instantiated without arguments, as in
lib/handle-request.js. Rather than reflecting the raw content-type
header value back to the client (which would expose unsanitized user
input in error responses and logs), the template is changed to the
static message 'Unsupported Media Type'.

This is a minor breaking change for consumers that match on the exact
error message string. The error code 'FST_ERR_CTP_INVALID_MEDIA_TYPE'
and HTTP status 415 are unchanged and should be used for programmatic
error handling instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@super-mcgin super-mcgin force-pushed the fix/ctp-invalid-media-type-message branch from 571297e to 7e26e1b Compare February 24, 2026 08:05
@super-mcgin super-mcgin changed the title fix: pass content-type value to FST_ERR_CTP_INVALID_MEDIA_TYPE fix: remove format placeholder from FST_ERR_CTP_INVALID_MEDIA_TYPE message Feb 24, 2026
@super-mcgin
Copy link
Contributor Author

super-mcgin commented Feb 24, 2026

@jsumners I've updated this so it never echoes the recevied value now. Technically this now would be considered a breaking change but I wouldn't think it warrants a major version update given it's only the message

Another alternative would be to simply pass a fixed string or an empty string to the original attempt at fixing it, which would retain the existing behaviour

@mcollina mcollina merged commit 1e0be12 into fastify:main Feb 28, 2026
38 checks passed
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.

3 participants