Skip to content

fix: Add secure flag to session middleware cookie configuration#22

Merged
galanko merged 1 commit into
masterfrom
opensec/fix/express-session-secure
May 15, 2026
Merged

fix: Add secure flag to session middleware cookie configuration#22
galanko merged 1 commit into
masterfrom
opensec/fix/express-session-secure

Conversation

@galanko
Copy link
Copy Markdown

@galanko galanko commented May 15, 2026

Summary

Automated remediation for semgrep finding: Default session middleware settings: secure not set. It ensures the browser only sends the cookie over HTTPS.

Changes

  • Added secure: true flag to the express-session cookie configuration
  • Uncommented and enabled the cookie security options (httpOnly: true and secure: true)
  • This ensures session cookies are only transmitted over HTTPS connections, preventing session hijacking via man-in-the-middle attacks on HTTP connections

Impact

  • Security improvement: Eliminates HTTP-based session hijacking vectors
  • No breaking changes: Configuration-level fix only
  • Requirement: Production environment must enforce HTTPS or use appropriate reverse proxy/load balancer SSL termination

Validation

The fix can be verified by:

  • Inspecting Set-Cookie headers to confirm Secure flag is present
  • Testing that cookies are rejected over plain HTTP connections
  • Verifying session functionality works correctly over HTTPS

Generated by OpenSec remediation agent

Adds 'secure: true' to the express-session cookie configuration to ensure
session cookies are only transmitted over HTTPS connections. This prevents
session hijacking via man-in-the-middle attacks on HTTP connections.

Fixes: javascript.express.security.audit.express-cookie-settings.express-cookie-session-no-secure
@galanko galanko marked this pull request as ready for review May 15, 2026 12:38
@galanko galanko merged commit cdea4bd into master May 15, 2026
@galanko galanko deleted the opensec/fix/express-session-secure branch May 15, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant