mds icon indicating copy to clipboard operation
mds copied to clipboard

Fix ZAP scan security vulnerabilities with proper CSP and security headers

Open Copilot opened this issue 5 months ago • 1 comments

This PR addresses multiple security vulnerabilities identified in the ZAP baseline security scan for minespace-test.apps.silver.devops.gov.bc.ca.

Issues Fixed

The ZAP scan identified several critical security issues:

  1. Content Security Policy (CSP) failures - Missing CSP directives for robots.txt and sitemap.xml endpoints
  2. Insufficient site isolation - Missing Cross-Origin headers to prevent Spectre-class vulnerabilities
  3. Improper cache control - Missing proper cache directives for static endpoints
  4. Missing security headers - Lack of X-Content-Type-Options and other protective headers

Changes Made

Added Explicit Security Endpoints

  • robots.txt endpoint with proper text/plain Content-Type and security headers
  • sitemap.xml endpoint with proper application/xml Content-Type and security headers
  • Trailing slash redirects (301) for both endpoints to handle URL variations

Enhanced Helmet Security Configuration

  • Default CSP policy when CONTENT_SECURITY_POLICY environment variable is not set
  • Cross-Origin-Embedder-Policy: require-corp for Spectre vulnerability mitigation
  • Cross-Origin-Opener-Policy: same-origin for process isolation
  • Cross-Origin-Resource-Policy: same-origin for resource protection

Security Headers Middleware

Added comprehensive security headers to all responses:

  • X-Content-Type-Options: nosniff to prevent MIME sniffing attacks
  • Referrer-Policy: strict-origin-when-cross-origin for privacy protection
  • Enhanced CORS headers for better isolation

Example

Before this fix, accessing /robots.txt would fall through to the static file handler without proper security headers:

GET /robots.txt
Response: 404 or fallback HTML with missing security headers

After this fix:

GET /robots.txt
Content-Type: text/plain
Cache-Control: public, max-age=86400
Cross-Origin-Resource-Policy: same-origin
X-Content-Type-Options: nosniff

User-agent: *
Disallow: /

Impact

  • Backward compatibility maintained - All existing endpoints continue to work unchanged
  • Minimal code changes - Only 2 files modified with surgical precision
  • Comprehensive security - Addresses all ZAP scan vulnerabilities
  • Performance neutral - No impact on existing functionality

The changes are applied to both minespace-web and core-web servers to ensure consistent security across all applications.

Fixes #3651.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Sep 19 '25 20:09 Copilot

@simensma-fresh 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot avatar Sep 19 '25 20:09 Copilot