From 0c58fb055b04a2e6e62d62007b6c8564c3578e98 Mon Sep 17 00:00:00 2001 From: Julio Felipe Angelini Date: Mon, 4 Feb 2019 17:38:01 -0200 Subject: [PATCH] fix(oas): parse headers as case insensitve Header name fields were not being handled as case-insensitive, which would cause unwanted authentication and validation errors. Refer RFC7230. Fixes #75 --- src/oas3/Operation.ts | 4 ++-- src/oas3/parameterParsers/index.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/oas3/Operation.ts b/src/oas3/Operation.ts index a4b3e6ab..ca0edea7 100644 --- a/src/oas3/Operation.ts +++ b/src/oas3/Operation.ts @@ -8,7 +8,7 @@ import { contentToRequestMediaTypeRegistry } from './oasUtils'; import RequestMediaType from './RequestMediaType'; import Oas3CompileContext from './Oas3CompileContext'; import Parameter from './Parameter'; -import { RawValues, parseParameterGroup, parseQueryParameters } from './parameterParsers'; +import { RawValues, parseParameterGroup, parseQueryParameters, parseHeaderParameters } from './parameterParsers'; import { ParametersMap, ParametersByLocation, @@ -211,7 +211,7 @@ export default class Operation { return { query: parseQueryParameters(this._parameters.query, queryString), - header: parseParameterGroup(this._parameters.header, headers || {}), + header: parseHeaderParameters(this._parameters.header, headers || {}), server: params.serverParams || {}, path: rawPathParams ? parseParameterGroup(this._parameters.path, rawPathParams) : {}, cookie: {} diff --git a/src/oas3/parameterParsers/index.ts b/src/oas3/parameterParsers/index.ts index 321820a0..fec3ba53 100644 --- a/src/oas3/parameterParsers/index.ts +++ b/src/oas3/parameterParsers/index.ts @@ -188,3 +188,17 @@ export function parseQueryParameters( const rawValues = querystring.parse(query || '', '&', '=', {decodeURIComponent: (val: string) => val}); return _parseParameterGroup(params, rawValues, query || ''); } + +export function parseHeaderParameters( + params: { + location: ParameterLocation, + parser: ParameterParser + }[], + rawHeaders: RawValues +) { + const rawValues = ld.mapKeys( + rawHeaders, + (_value: string | string[] | undefined, key: string) => key.toLowerCase() + ); + return _parseParameterGroup(params, rawValues, ''); +} \ No newline at end of file