Potential fix for code scanning alert no. 4: Clear text transmission of sensitive cookie#2
Merged
Code-lab-web merged 1 commit intomainfrom Feb 16, 2026
Merged
Conversation
…of sensitive cookie Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/Code-lab-web/project-final/security/code-scanning/4
In general, to fix this issue you must configure the session cookie to have
secure: trueso it is only sent over HTTPS, and ideally also sethttpOnly: true(not directly related to this finding but a best practice). When running behind a reverse proxy that terminates TLS, Express also needsapp.set('trust proxy', 1)so thatexpress-sessionrespectscookie.secureeven though the direct connection to Node is HTTP.The best fix here is to update each
app.use(session({ ... }))call inbackend/app.jsto include acookiefield withsecure: trueandhttpOnly: true, and to ensureapp.set('trust proxy', 1)is configured once after creating the Express app. We must not change existing functionality apart from tightening cookie security, so we will keep all existing options (secret,resave,saveUninitialized,store) unchanged. The file contains three separate session initializations (lines 28–33, 63–68, 95–100); all three should be updated consistently. No new imports are required; we only adjust the configuration object and add thetrust proxysetting.Concretely:
var app = express();(first definition, line 14) addapp.set('trust proxy', 1);.cookieblock to the session configs at lines 63–68 and 95–100.We leave the rest of the code unchanged.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.