Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ export class ResponseHeadersPolicy extends Resource implements IResponseHeadersP
throw new ValidationError(`accessControlAllowMethods contains unexpected method name; allowed values: ${allowedMethods.join(', ')}`, this);
}
});
withResolved(behavior.accessControlAllowHeaders, (headers) => {
if (behavior.accessControlAllowCredentials && headers.some(header => !Token.isUnresolved(header) && header.includes('*'))) {
throw new ValidationError('accessControlAllowHeaders cannot contain "*" or headers with "*" when accessControlAllowCredentials is true', this);
}
});

return {
accessControlAllowCredentials: behavior.accessControlAllowCredentials,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,20 @@ describe('ResponseHeadersPolicy', () => {
},
})).toThrow(/accessControlAllowMethods contains unexpected method name/);
});

test.each([
[['*']],
[['X-Custom-*', 'Authorization']],
])('throws if accessControlAllowHeaders contains wildcard when accessControlAllowCredentials is true', (headers) => {
expect(() => new ResponseHeadersPolicy(stack, 'ResponseHeadersPolicy', {
corsBehavior: {
accessControlAllowCredentials: true,
accessControlAllowHeaders: headers,
accessControlAllowMethods: ['GET'],
accessControlAllowOrigins: ['https://example.com'],
originOverride: true,
},
})).toThrow('accessControlAllowHeaders cannot contain "*" or headers with "*" when accessControlAllowCredentials is true');
});
});
});
Loading