Skip to content

Commit 3872241

Browse files
committed
fix: Add type guard for CSPReport validation
- Fix TypeScript error when validating unknown CSP reports - Add explicit type narrowing with Record<string, unknown> - Maintains same runtime behavior with proper type safety
1 parent 20091d4 commit 3872241

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/security/security-headers.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,14 @@ export interface CSPReport {
493493
}
494494

495495
export function validateCSPReport(report: unknown): report is CSPReport {
496+
if (typeof report !== 'object' || report === null) {
497+
return false;
498+
}
499+
500+
const r = report as Record<string, unknown>;
496501
return (
497-
typeof report === 'object' &&
498-
report !== null &&
499-
typeof report['document-uri'] === 'string' &&
500-
typeof report['violated-directive'] === 'string' &&
501-
typeof report['blocked-uri'] === 'string'
502+
typeof r['document-uri'] === 'string' &&
503+
typeof r['violated-directive'] === 'string' &&
504+
typeof r['blocked-uri'] === 'string'
502505
);
503506
}

0 commit comments

Comments
 (0)