Skip to content

[Security] Harden session cookie with HttpOnly, Secure, and SameSite flags#456

Closed
advikdivekar wants to merge 1 commit into
GitMetricsLab:mainfrom
advikdivekar:security/session-cookie-flags-373
Closed

[Security] Harden session cookie with HttpOnly, Secure, and SameSite flags#456
advikdivekar wants to merge 1 commit into
GitMetricsLab:mainfrom
advikdivekar:security/session-cookie-flags-373

Conversation

@advikdivekar
Copy link
Copy Markdown
Contributor

@advikdivekar advikdivekar commented May 23, 2026

Problem

backend/server.js configured express-session with no cookie security attributes. The resulting connect.sid cookie had:

  • No HttpOnly flag — JavaScript running in the page (including any XSS gadget or compromised npm package) could read document.cookie and exfiltrate the session ID, achieving full account takeover.
  • No Secure flag — the cookie was transmitted over plain HTTP, allowing any network observer on shared Wi-Fi, an ISP, or a transparent proxy to capture and replay the session ID.
  • No SameSite flag — cross-site requests (e.g. an <img> tag on a third-party page pointing at /api/auth/logout) automatically carried the cookie, enabling CSRF attacks on all current and future authenticated endpoints.

Additionally, backend/Dockerfile.prod did not set NODE_ENV=production, so the secure: process.env.NODE_ENV === 'production' check would never activate in the containerised deployment.

Changes

backend/server.js

  • Added cookie block to the express-session configuration with:
    • httpOnly: true — cookie is invisible to JavaScript in all environments
    • secure: process.env.NODE_ENV === 'production' — HTTPS-only in production
    • sameSite: 'strict' in production, 'lax' in development — blocks cross-site cookie sending while keeping local dev workflow functional
    • maxAge: 24 * 60 * 60 * 1000 — 24-hour expiry

backend/Dockerfile.prod

  • Added ENV NODE_ENV=production so the secure flag correctly activates when the container is deployed.

Why this approach fixes the root cause

The three flags address three independent attack vectors at the browser level before any application logic runs. Setting secure conditionally on NODE_ENV preserves the local development experience (HTTP over localhost) while enforcing HTTPS-only in production. Setting sameSite: 'strict' in production eliminates the CSRF surface on all authenticated endpoints without requiring per-endpoint CSRF token middleware.

Steps to test

  1. Start the backend (npm start in backend/).
  2. POST to /api/auth/login with valid credentials.
  3. Inspect the Set-Cookie response header — confirm it contains HttpOnly, SameSite=Lax (dev), and no Secure flag in dev mode.
  4. Build and run the production Docker image (docker build -f Dockerfile.prod -t tracker-prod .).
  5. POST to /api/auth/login — confirm Set-Cookie now shows Secure; HttpOnly; SameSite=Strict.
  6. In a browser console on the running app, run document.cookie — confirm connect.sid is not present.

Edge cases covered

  • Development (HTTP localhost) — SameSite=Lax and no Secure flag so login still works without HTTPS.
  • Production Docker deployment — NODE_ENV=production is set in the Dockerfile, activating Secure and SameSite=Strict automatically.
  • Any XSS injection attempt — HttpOnly blocks cookie access in all environments.

Regression check

No existing routes, middleware, or tests were modified. Session serialization/deserialization logic in passportConfig.js is unchanged. The cookie attribute changes are transparent to all application code that reads from req.session or req.user.

Please review and merge this under GSSoC 2026.

Summary by CodeRabbit

  • Chores
    • Configured production environment settings for container deployment
    • Enhanced session security with improved cookie protection settings including HTTP-only protection and same-site policies

Review Change Stack

Set httpOnly to block JS access, secure to enforce HTTPS-only
transmission in production, and sameSite to prevent cross-site
requests from carrying the session cookie. Add NODE_ENV=production
to the production Dockerfile so the secure flag activates correctly
when deployed.

Fixes GitMetricsLab#373
@netlify
Copy link
Copy Markdown

netlify Bot commented May 23, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit 9412333
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a11bb4058e0af0008c93b9a
😎 Deploy Preview https://deploy-preview-456--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b997b2ce-b852-4c3c-b32d-a7bb0bf97e36

📥 Commits

Reviewing files that changed from the base of the PR and between 373dde2 and 9412333.

📒 Files selected for processing (2)
  • backend/Dockerfile.prod
  • backend/server.js
 ________________________________________
< C*deR*bb*t: The uncensored bug hunter. >
 ----------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can suggest fixes for GitHub Check annotations.

Configure the reviews.tools.github-checks setting to adjust the time to wait for GitHub Checks to complete.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 23, 2026

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{"name":"HttpError","status":401,"request":{"method":"PATCH","url":"https://api.github.com/repos/GitMetricsLab/github_tracker/issues/comments/4525681921","headers":{"accept":"application/vnd.github.v3+json","user-agent":"octokit.js/0.0.0-development octokit-core.js/7.0.6 Node.js/24","authorization":"token [REDACTED]","content-type":"application/json; charset=utf-8"},"body":{"body":"<!-- This is an auto-generated comment: summarize by coderabbit.ai -->\n<!-- walkthrough_start -->\n\n<details>\n<summary>📝 Walkthrough</summary>\n\n## Walkthrough\n\nThe PR hardens the production deployment and session security by adding an explicit `NODE_ENV=production` environment variable to the Docker production image and configuring express-session with explicit, environment-aware cookie security attributes (httpOnly, secure, sameSite, and maxAge).\n\n## Changes\n\n**Production Environment and Session Security**\n\n| Layer / File(s) | Summary |\n| --- | --- |\n| **Docker production environment setup** <br> `backend/Dockerfile.prod` | Adds `ENV NODE_ENV=production` directive to configure the container to run in production mode. |\n| **Session cookie security hardening** <br> `backend/server.js` | Express-session middleware now explicitly sets `httpOnly: true`, `secure` conditional on `NODE_ENV`, `sameSite` conditional on `NODE_ENV`, and `maxAge` to 24 hours instead of using defaults. |\n\n## Estimated code review effort\n\n🎯 2 (Simple) | ⏱️ ~10 minutes\n\n## Possibly related issues\n\n- **`#447`**: Session cookie hardening through explicit httpOnly, secure, sameSite, and maxAge settings directly implements the security objectives described in this issue.\n- **`#373`**: These changes implement the identical code-level fixes: NODE_ENV=production in the Dockerfile and explicit session cookie security options in server.js.\n\n## Poem\n\n> 🐰 A rabbit hops through Docker files,  \n> Sets NODE_ENV with careful smiles,  \n> Session cookies, sealed up tight,  \n> httpOnly, secure, sameSite—  \n> Production ready, safe and sound! 🔒\n\n</details>\n\n<!-- walkthrough_end -->\n<!-- pre_merge_checks_walkthrough_start -->\n\n<details>\n<summary>🚥 Pre-merge checks | ✅ 5</summary>\n\n<details>\n<summary>✅ Passed checks (5 passed)</summary>\n\n|         Check name         | Status   | Explanation                                                                                                                                                                             |\n| :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n|         Title check        | ✅ Passed | The title accurately summarizes the primary security hardening change—adding HttpOnly, Secure, and SameSite flags to the session cookie.                                                |\n|      Description check     | ✅ Passed | The description is comprehensive, covering problem statement, detailed changes, rationale, test steps, and edge cases. However, the related issue section from the template is missing. |\n|     Docstring Coverage     | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.                                                                              |\n|     Linked Issues check    | ✅ Passed | Check skipped because no linked issues were found for this pull request.                                                                                                                |\n| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request.                                                                                                                |\n\n</details>\n\n<sub>✏️ Tip: You can configure your own custom pre-merge checks in the settings.</sub>\n\n</details>\n\n<!-- pre_merge_checks_walkthrough_end -->\n<!-- finishing_touch_checkbox_start -->\n\n<details>\n<summary>✨ Finishing Touches</summary>\n\n<details>\n<summary>🧪 Generate unit tests (beta)</summary>\n\n- [ ] <!-- {\"checkboxId\": \"f47ac10b-58cc-4372-a567-0e02b2c3d479\", \"radioGroupId\": \"utg-output-choice-group-unknown_comment_id\"} -->   Create PR with unit tests\n\n</details>\n\n</details>\n\n<!-- finishing_touch_checkbox_end -->\n<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->\n\n> [!WARNING]\n> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.\n> \n> <details>\n> <summary>🔧 ESLint</summary>\n> \n> > If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.\n> \n> <details>\n> <summary>backend/server.js</summary>\n> \n> ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.\n> \n> </details>\n> \n> </details>\n\n<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->\n<!-- tips_start -->\n\n---\n\nThanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=GitMetricsLab/github_tracker&utm_content=456)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.\n\n<details>\n<summary>❤️ Share</summary>\n\n- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)\n- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)\n- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)\n- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)\n\n</details>\n\n\n<sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub>\n\n<!-- tips_end -->\n<!-- internal state start -->\n\n\n<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKPR1AGxJcA2gGVRbAp1WQBdSAAJZyUsRGlEeHwsJnwAa3gSSAB3dVhI3FxuAHkMD1kAGkgAhiCSSsx6PzQ2P3VMgDMPNCJkAApbSDMAFgBWADYASkhIAwBBPFh8Ci40Wgl4VNpJElTnaYMAISoMBlguOJrg3FkAejjEBKSwFPSSME7uxDAAZgB2b8ggCTCSDMbRYGZ+XDUbCILj4bhkfYAVRsABkuLACtxYTcbkRctgBBomMwbgBxdQAWRIuGCDEQqJUeIJAgA+rS0AxUpQbtxsB4PDdRmN9gBhCgkah0LgAJgADDKxmA5SMwDLvtAAIxDDjfEYcIYygBaRgAItIGMFuOIkhwDFArBRBF5mFwBJzuRhaHdKFIKBohMgmBh2vAiLV6CQAB68eJge6PLA5XCLPAKNIZeyBK7yai0+ACPDSSpeNDrDBESApzIJxLJfAZzK9AAGwfIYg0CVozamEn55CoAi8VfwVdgJHauEg6zQkAAGn4/JBehhRxEsSUyhNKuRcFklqlGGhrbUbhLuF15Pg/ZFoNArMvV1VsyRt+gvZBRX4bAAxR+jpoWjaCYNEgd0uTIb1TXwCCKFDLwNF4RR0A8RBRy2ehVynOIpwAOSKU0AFFWUI3CADUAF4kNobAxDrSpYykDBxArBQvXUOs0A8Z9LkyTlxAkag6xQetmLBShEA0e1P1gTBSFhAxpigcDPW9OIKD9ANYUgWZaCUehZxeTMhxgw8CEgaNYweeN4mE5MzkU6ZdEgTFCk3WQuFpbASEcpSs14rgkIYeINDICQNHwoiSPIyAKLiyAAHJqNom0MAS3znMQZoSFaGguASxB8zEBKRJ4J0aLopJKgS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lDHQnJHODwlEAsm/7YklEeBlH4mEGKm2nskkliHxGGnUmtF1ZMGQAsEOB2zdGkmslQjqHskDGlm/7ckWmoF8H2DqkIj0ACAx4wiZBPgMH5kfGCx+48zCkfj2moB8gCj0IACObBmgsZUJWykZqR6R1ZqB8ZZ+iZeJFRrRXZdAhZbBswDw8QTSaaEhtRTk5Jkh2ZyZNyRQaY3yfgTACIMktiXqShi5VW5Z/RVYtB8RtZdYnBDZiATZparZ/s7ZIiTMDU3ZrBvZiqQpIpQpfAKYw5/I3EEoE5UcYZkhEZrRcJC5hRwQOJq5MhF5wpuARQ7Qt58IJA8Bj5u5CYB5NRjkoQ3BiSuAtg7RRJP5rRaAdAIwIw4eAg8etA7Wmo7QKWtA6WGWue/2IwDAYeQwIlOeCW7QtA7QJAYwaAKl6edA7Qqe7W3wAgCWCW4ePF7QAgmo7WvwPR9BzFtgChnBvwYwjW2lYwkojWIwQw5l7QI00lKetAXFtADACWcoeeDAcov2CW3wqemoaACWv2ou00JlBetAUVcoQwReIlmovwmoaa92WuTeLebehpXu9ezuJmlmrICS7ZAe5ZJAVVNWPeYWPBLF3sW6swuAAhAmdAY+6gbM68uAMWcoOVBgLuZVFVcQtVNArIxVegQAA= -->\n\n<!-- internal state end -->"},"request":{"retryCount":1,"signal":{}}},"response":{"url":"https://api.github.com/repos/GitMetricsLab/github_tracker/issues/comments/4525681921","status":401,"headers":{"access-control-allow-origin":"*","access-control-expose-headers":"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset","connection":"close","content-security-policy":"default-src 'none'","content-type":"application/json; charset=utf-8","date":"Sat, 23 May 2026 14:39:53 GMT","referrer-policy":"origin-when-cross-origin, strict-origin-when-cross-origin","server":"github.com","strict-transport-security":"max-age=31536000; includeSubdomains; preload","vary":"Accept-Encoding, Accept, X-Requested-With","x-content-type-options":"nosniff","x-frame-options":"deny","x-github-media-type":"github.v3; format=json","x-github-request-id":"0511:26E031:B23CAC8:2AF94B1A:6A11BC39","x-xss-protection":"0"},"data":{"message":"Bad credentials","documentation_url":"https://docs.github.com/rest","status":"401"}}}

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/server.js (1)

19-29: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Add a production-grade session store (store)
backend/server.js config for app.use(session({ ... })) omits store, so express-session uses the default in-memory store. In production this won’t survive restarts and won’t work across multiple app instances, making the 24h maxAge misleading for authenticated sessions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/server.js` around lines 19 - 29, The session middleware block
(app.use(session({...}))) currently omits the store option and thus uses the
default in-memory store; replace that by wiring a production-grade session store
(e.g., RedisStore from connect-redis or MongoStore from connect-mongo) and pass
an instantiated store object into the session configuration under the store key;
initialize the chosen store (e.g., create a Redis client and new RedisStore({
client })) before calling app.use(session(...)), read credentials from env vars,
and keep existing settings (secret, cookie, resave, saveUninitialized) while
ensuring secure cookie behavior in production.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/server.js`:
- Around line 25-26: Express is configuring session cookies with secure:
process.env.NODE_ENV === 'production' but never sets app.set('trust proxy',
...), so when HTTPS is terminated upstream the app won't see requests as secure
and cookies may not be sent; add a call like app.set('trust proxy', 1) (or
app.set('trust proxy', process.env.TRUST_PROXY || 1) / conditional when
process.env.NODE_ENV === 'production') in the server initialization (before
express-session is used) to ensure req.secure is populated, and confirm the
ingress/proxy forwards X-Forwarded-Proto.

---

Outside diff comments:
In `@backend/server.js`:
- Around line 19-29: The session middleware block (app.use(session({...})))
currently omits the store option and thus uses the default in-memory store;
replace that by wiring a production-grade session store (e.g., RedisStore from
connect-redis or MongoStore from connect-mongo) and pass an instantiated store
object into the session configuration under the store key; initialize the chosen
store (e.g., create a Redis client and new RedisStore({ client })) before
calling app.use(session(...)), read credentials from env vars, and keep existing
settings (secret, cookie, resave, saveUninitialized) while ensuring secure
cookie behavior in production.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b997b2ce-b852-4c3c-b32d-a7bb0bf97e36

📥 Commits

Reviewing files that changed from the base of the PR and between 373dde2 and 9412333.

📒 Files selected for processing (2)
  • backend/Dockerfile.prod
  • backend/server.js

Comment thread backend/server.js
Comment on lines +25 to +26
secure: process.env.NODE_ENV === 'production',
sameSite: process.env.NODE_ENV === 'production' ? 'strict' : 'lax',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether the backend already trusts an upstream proxy
rg -nP --type=js -C2 "app\.set\(\s*['\"]trust proxy['\"]|proxy\s*:\s*true" backend

Repository: GitMetricsLab/github_tracker

Length of output: 54


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== trust proxy (repo-wide) =="
rg -n --type=js "trust proxy" .

echo "== express-session usage (repo-wide) =="
rg -n --type=js "express-session" .

echo "== session cookie options (repo-wide) =="
rg -n --type=js "cookie\s*:\s*\{[^}]*secure" . || true

Repository: GitMetricsLab/github_tracker

Length of output: 102


🏁 Script executed:

#!/bin/bash
set -u

echo "== trust proxy (repo-wide) =="
rg -n --type=js "trust proxy" . || true

echo "== express-session usage (repo-wide) =="
rg -n --type=js "express-session" . || true

echo "== session middleware / cookie secure options (repo-wide) =="
rg -n --type=js -S "cookie\s*:\s*\{|\bcookie\b.*secure:|secure:\s*process\.env\.NODE_ENV\s*===\s*'production'|secure:\s*true" .

echo "== likely app/session config files (backend) =="
ls -la backend

Repository: GitMetricsLab/github_tracker

Length of output: 1146


🏁 Script executed:

#!/bin/bash
set -euo pipefail
nl -ba backend/server.js | sed -n '1,90p'

Repository: GitMetricsLab/github_tracker

Length of output: 115


🏁 Script executed:

#!/bin/bash
set -euo pipefail
awk 'NR>=1 && NR<=90 {print NR ":" $0}' backend/server.js

Repository: GitMetricsLab/github_tracker

Length of output: 1416


Set trust proxy when behind a TLS-terminating reverse proxy/ingress.

backend/server.js configures express-session cookies with secure: process.env.NODE_ENV === 'production', but the Express app never sets app.set('trust proxy', ...). If HTTPS is terminated upstream, Express may not treat requests as secure, and the cookie may not be set in production—leading to broken sessions/auth. Add app.set('trust proxy', <value>) (and ensure the proxy forwards X-Forwarded-Proto) when deployed behind a proxy.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/server.js` around lines 25 - 26, Express is configuring session
cookies with secure: process.env.NODE_ENV === 'production' but never sets
app.set('trust proxy', ...), so when HTTPS is terminated upstream the app won't
see requests as secure and cookies may not be sent; add a call like
app.set('trust proxy', 1) (or app.set('trust proxy', process.env.TRUST_PROXY ||
1) / conditional when process.env.NODE_ENV === 'production') in the server
initialization (before express-session is used) to ensure req.secure is
populated, and confirm the ingress/proxy forwards X-Forwarded-Proto.

@advikdivekar
Copy link
Copy Markdown
Contributor Author

@mehul-m-prajapati why was my code not merged? did i make any mistakes in my code? please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants