Skip to content

Commit 9e95ca1

Browse files
authored
fix: wildcards being quoted (#6)
1 parent 3902b7a commit 9e95ca1

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/csp.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type HttpDelineators = typeof httpDelineators[number];
2929
type UriPath = `${HttpDelineators}${string}`
3030

3131
// Base Source Directives
32-
export const baseSources = ['self', 'unsafe-eval', 'unsafe-hashes', 'unsafe-inline', 'none'] as const;
32+
export const baseSources = ['self', 'unsafe-eval', 'unsafe-hashes', 'unsafe-inline', 'none', '*'] as const;
3333
type BaseSources = typeof baseSources[number]
3434

3535
// Combined all source directives

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const PolicySet = new Set([
6363
...sandboxDirectives,
6464
]);
6565
function isQuotedPolicy (policy: string): boolean {
66+
if (policy === '*') return false;
6667
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
6768
// @ts-ignore
6869
if (PolicySet.has(policy)) return true;

tests/basic.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,18 @@ describe('new CspDirectives()',() => {
107107
}
108108
expect(inst.getHeaders).toThrowError();
109109
});
110+
111+
it('supports wildcards',() => {
112+
const csp: Directives = {
113+
'style-src': ['*', 'data:'],
114+
};
115+
const inst = new CspDirectives(csp, [], csp);
116+
expect(inst.getHeaders()).toStrictEqual({
117+
'Content-Security-Policy-Report-Only': 'style-src * data:;',
118+
'Content-Security-Policy': "style-src * data:;",
119+
'Report-To': '',
120+
'Referrer-Policy': 'strict-origin-when-cross-origin',
121+
});
122+
});
110123
});
111124
});

0 commit comments

Comments
 (0)