Skip to content

Conversation

@hrntknr
Copy link
Member

@hrntknr hrntknr commented Aug 20, 2025

Summary

Add security improvements to session cookies by configuring HttpOnly flag and MaxAge timeout to enhance protection against XSS attacks and improve session management.

Type of Change

  • feat: A new feature

Related Issues

Add HttpOnly flag to prevent XSS attacks on session cookies and set MaxAge to 3600 seconds (1 hour) for better session management
Copilot AI review requested due to automatic review settings August 20, 2025 13:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances session security by configuring cookie options to protect against XSS attacks and improve session lifecycle management.

  • Adds HttpOnly flag to session cookies to prevent client-side JavaScript access
  • Sets MaxAge to 3600 seconds (1 hour) for automatic session expiration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

router.Use(ginzap.RecoveryWithZap(logger, true))
store := cookie.NewStore(secret)
store.Options(sessions.Options{
MaxAge: 3600,
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MaxAge value of 3600 seconds (1 hour) is hardcoded. Consider making this configurable through environment variables or configuration files to allow different timeout values across environments.

Suggested change
MaxAge: 3600,
// Make session MaxAge configurable via environment variable
maxAge := 3600
if v := os.Getenv("SESSION_MAX_AGE"); v != "" {
if parsed, err := strconv.Atoi(v); err == nil && parsed > 0 {
maxAge = parsed
}
}
store.Options(sessions.Options{
MaxAge: maxAge,

Copilot uses AI. Check for mistakes.
store := cookie.NewStore(secret)
store.Options(sessions.Options{
MaxAge: 3600,
HttpOnly: true,
Copy link

Copilot AI Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The session options are missing the Secure flag which should be set to true in production to ensure cookies are only transmitted over HTTPS connections.

Suggested change
HttpOnly: true,
store := cookie.NewStore(secret)
secureCookie := parsedExternalURL.Scheme == "https"
store.Options(sessions.Options{
MaxAge: 3600,
HttpOnly: true,
Secure: secureCookie,

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Aug 20, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/mcp-proxy/main.go 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@hrntknr hrntknr merged commit 9038812 into main Aug 20, 2025
7 checks passed
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.

2 participants