Skip to content

security: Tighten CSP to remove unsafe-inline for styles #223

@Xhristin3

Description

@Xhristin3

Problem Statement

The Helmet CSP in api/src/main.ts:25 permits 'unsafe-inline' for styles to support Swagger UI. This weakens the Content Security Policy globally for all API responses, including non-Swagger routes.

Evidence

styleSrc: ["'self'", "'unsafe-inline'"],

Impact

XSS attacks that inject <style> tags or use inline style attributes may bypass CSP. The unsafe-inline directive weakens the primary defense against CSS injection attacks.

Proposed Solution

  1. Serve Swagger UI under /docs with a separate, relaxed CSP (using a route-specific middleware or helmet.route-specific config)
  2. Remove 'unsafe-inline' from the global CSP
  3. Add nonce-based inline style support if needed

Acceptance Criteria

  • Global CSP does not include 'unsafe-inline'
  • Swagger UI at /docs still renders correctly
  • Swagger-specific CSP allows required styles

File Map

  • api/src/main.ts — tighten global CSP
  • api/src/swagger-csp.middleware.ts — new relaxed CSP for /docs

Labels: security
Priority: Low | Difficulty: Intermediate | Estimated Effort: 1d


Labels: security
Priority: Low | Difficulty: Intermediate | Estimated Effort: 1d
Backlog ID: REPO-040

Metadata

Metadata

Assignees

Labels

securitySecurity related issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions