Validate Content-Type by parsed media type instead of substring match (v1.x) (#2444)

This commit is contained in:
Felix Weinberger 2026-07-06 21:03:35 +01:00 • committed by GitHub
commit 69749aa508
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,6 +23,23 @@ export default tseslint.config(
{
ignores: ['src/spec.types.ts']
},
{
files: ['src/**/*.ts'],
rules: {
'no-restricted-syntax': [
'error',
{
selector:
":matches(CallExpression[callee.property.name='includes'], CallExpression[callee.property.name='indexOf'], " +
"CallExpression[callee.property.name='startsWith'])[arguments.0.value='application/json']",
message:
"Substring-matching 'application/json' misclassifies Content-Type values whose media type is different " +
"(e.g. 'text/plain; a=application/json') and mishandles parameters and case. " +
'Parse the media type instead: isJsonContentType() from src/shared/mediaType.js.'
}
]
}
},
{
files: ['src/client/**/*.ts', 'src/server/**/*.ts'],
ignores: ['**/*.test.ts'],