Skip to content

Commit

Permalink
fix(cloudfront): Origin Request Policy headers enforce soft limit of 10
Browse files Browse the repository at this point in the history
  • Loading branch information
robertd committed Mar 31, 2021
1 parent 7108c3a commit 04c3ebf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 14 deletions.
3 changes: 0 additions & 3 deletions packages/@aws-cdk/aws-cloudfront/lib/origin-request-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ export class OriginRequestHeaderBehavior {
if (headers.length === 0) {
throw new Error('At least one header to allow must be provided');
}
if (headers.length > 10) {
throw new Error(`Maximum allowed headers in Origin Request Policy is 10; got ${headers.length}.`);
}
if (/Authorization/i.test(headers.join('|')) || /Accept-Encoding/i.test(headers.join('|'))) {
throw new Error('you cannot pass `Authorization` or `Accept-Encoding` as header values; use a CachePolicy to forward these headers instead');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,6 @@ describe('OriginRequestPolicy', () => {
expect(() => new OriginRequestPolicy(stack, 'OriginRequestPolicy7', { headerBehavior: OriginRequestHeaderBehavior.allowList('Foo', 'Bar') })).not.toThrow();
});

test('throws if more than 10 OriginRequestHeaderBehavior headers are being passed', () => {
const errorMessage = /Maximum allowed headers in Origin Request Policy is 10; got (.*?)/;
expect(() => new OriginRequestPolicy(stack, 'OriginRequestPolicy1', {
headerBehavior: OriginRequestHeaderBehavior.allowList('Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'sed', 'do', 'eiusmod'),
})).toThrow(errorMessage);

expect(() => new OriginRequestPolicy(stack, 'OriginRequestPolicy2', {
headerBehavior: OriginRequestHeaderBehavior.allowList('Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'sed', 'do'),
})).not.toThrow();
});

test('does not throw if originRequestPolicyName is a token', () => {
expect(() => new OriginRequestPolicy(stack, 'CachePolicy', {
originRequestPolicyName: Aws.STACK_NAME,
Expand Down

0 comments on commit 04c3ebf

Please sign in to comment.