Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function checkCSP(headers: RawHeaders): HeaderFinding {
// fetch/navigation directive — not just as the first token of default-src/
// script-src. img-src/style-src/font-src/media-src are intentionally omitted
// as a wildcard there is low-risk and commonly legitimate.
const wildcardDirectives = ['default-src', 'script-src', 'connect-src', 'form-action', 'frame-src', 'worker-src'];
const wildcardDirectives = ['default-src', 'script-src', 'connect-src', 'form-action', 'frame-src', 'worker-src', 'object-src'];
const wildcarded = wildcardDirectives.filter(d => {
const sources = extractCspDirective(raw, d);
return sources !== undefined && sources.some(isPermissiveSource);
Expand Down
17 changes: 17 additions & 0 deletions test/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ describe('checkCSP', () => {
expect(r.findings.some(f => /Wildcard or bare-scheme/i.test(f))).toBe(false);
});

it('detects wildcard in object-src', () => {
const r = checkCSP({ 'content-security-policy': "default-src 'self'; form-action 'self'; base-uri 'self'; object-src *" });
expect(r.findings.some(f => /Wildcard.*object-src/i.test(f))).toBe(true);
expect(r.score).toBeLessThan(20);
});

it('detects bare scheme in object-src', () => {
const r = checkCSP({ 'content-security-policy': "default-src 'self'; form-action 'self'; base-uri 'self'; object-src https:" });
expect(r.findings.some(f => /Wildcard or bare-scheme/i.test(f))).toBe(true);
});

it("does not flag restrictive object-src 'none'", () => {
const r = checkCSP({ 'content-security-policy': "default-src 'self'; form-action 'self'; base-uri 'self'; object-src 'none'" });
expect(r.findings.some(f => /object-src/i.test(f))).toBe(false);
expect(r.score).toBe(20);
});

it('clean CSP returns score 20', () => {
const r = checkCSP({ 'content-security-policy': "default-src 'self'; form-action 'self'; base-uri 'self'" });
expect(r.score).toBe(20);
Expand Down
Loading