Hello,
I recently noticed some requests for which it seemed the schema validation was not performed. Upon investigation, I noticed these requests had in common malformed Content-Type headers, for example: multipart/form-data, application/json.
Committee is extracting the media type from the header in 2 place:
First, it's done in https://github.com/interagent/committee/blob/v5.6.0/lib/committee/schema_validator/open_api_3/request_validator.rb#L15 to check if the request content type is defined in the schema. It's using ActionDispatch::Http::MimeNegotiation#content_mime_type. Here, a malformed content-type like multipart/form-data, application/json is interpreted as multipart/form-data.
Assuming the schema handles this mime type, the process continues. Later, Committee extract the content type again, but this time by splitting using ; as a delimiter in https://github.com/interagent/committee/blob/v5.6.0/lib/committee/schema_validator/open_api_3/operation_wrapper.rb#L114 and pass this content-type to the request validation handled by openapi_parser.
Splitting on ; means that in this case we are passing multipart/form-data, application/json to the openapi_parser gem and it does not manage to extract the media type, returns nil and effectively just bypass the validation in https://github.com/ota42y/openapi_parser/blob/5cbe0772d9b2a4f8345c6c2ded1a05dee1b7b7d1/lib/openapi_parser/schemas/request_body.rb#L22.
I'm not sure what should be the fix, but at least I guess the content type extraction should be consistent.
Hello,
I recently noticed some requests for which it seemed the schema validation was not performed. Upon investigation, I noticed these requests had in common malformed Content-Type headers, for example:
multipart/form-data, application/json.Committee is extracting the media type from the header in 2 place:
First, it's done in https://github.com/interagent/committee/blob/v5.6.0/lib/committee/schema_validator/open_api_3/request_validator.rb#L15 to check if the request content type is defined in the schema. It's using
ActionDispatch::Http::MimeNegotiation#content_mime_type. Here, a malformed content-type likemultipart/form-data, application/jsonis interpreted asmultipart/form-data.Assuming the schema handles this mime type, the process continues. Later, Committee extract the content type again, but this time by splitting using
;as a delimiter in https://github.com/interagent/committee/blob/v5.6.0/lib/committee/schema_validator/open_api_3/operation_wrapper.rb#L114 and pass this content-type to the request validation handled byopenapi_parser.Splitting on
;means that in this case we are passingmultipart/form-data, application/jsonto the openapi_parser gem and it does not manage to extract the media type, returns nil and effectively just bypass the validation in https://github.com/ota42y/openapi_parser/blob/5cbe0772d9b2a4f8345c6c2ded1a05dee1b7b7d1/lib/openapi_parser/schemas/request_body.rb#L22.I'm not sure what should be the fix, but at least I guess the content type extraction should be consistent.