Repository navigation
Conversation
1 task done
…ey and missing-rate-limiting regression tests Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
| const bodyParser = require('body-parser'); | ||
| const app = express(); | ||
| app.use(bodyParser.urlencoded({ extended: false })); | ||
| app.use(session({ secret: 'keyboard cat' })); |
| const routes = require("./routes"); | ||
|
|
||
| MongoClient.connect("mongodb://localhost/db", (err, db) => { | ||
| app.use(session({ secret: "secret", saveUninitialized: true, resave: true })); |
|
|
||
| const router = express.Router(); | ||
|
|
||
| router.get('/accounts/:username/profile', auth, (req, res) => { // $ Alert |
|
|
||
| app.get("/login", sessionHandler.displayLoginPage); | ||
| app.post("/login", sessionHandler.handleLoginRequest); // $ Alert | ||
| app.post("/safe-login", sessionHandler.handleSafeLoginRequest); |
|
|
||
| var app = express(); | ||
| app.get('/login', routes.login); | ||
| app.post('/login', routes.loginHandler); // $ Alert |
| const sessionHandler = new SessionHandler(db); | ||
|
|
||
| app.get("/login", sessionHandler.displayLoginPage); | ||
| app.post("/login", sessionHandler.handleLoginRequest); // $ Alert |
|
|
||
| // GOOD: the login handler is rate-limited. | ||
| var loginLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 5 }); | ||
| app.post('/limited-login', loginLimiter, routes.loginHandler); |
|
|
||
| var app = express(); | ||
| app.get('/login', routes.login); | ||
| app.post('/login', routes.loginHandler); // $ Alert |
| const bodyParser = require('body-parser'); | ||
| const app = express(); | ||
| app.use(bodyParser.urlencoded({ extended: false })); | ||
| app.use(session({ secret: 'keyboard cat' })); |
| const bodyParser = require('body-parser'); | ||
| const app = express(); | ||
| app.use(bodyParser.urlencoded({ extended: false })); | ||
| app.use(session({ secret: 'keyboard cat' })); |
…nd match lower-case header names Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Copilot Request
[UPDATE QUERY] JavaScript: track req.session across calls in js/session-fixation, add js/rate-limit-spoofable-key (CWE-384, CWE-307)
Oct 31, 2026
There was a problem hiding this comment.
🟡 Changes recommended
The query loses limiter and application trust context, causing false positives for shared key generators and sub-app trust overrides, plus false negatives for unresolved router mounts.
3 open issues
What changed in this PR
This PR addresses the confirmed detection gaps from issue #358 in the JavaScript custom CodeQL pack, while adding regression tests for cases already covered by stock queries.
Changes:
- Extends session-fixation detection to follow session objects into helper functions.
- Adds a query for rate-limit keys derived from spoofable client-address values.
- Adds positive and negative fixtures, query help, examples, and a change note.
| File | Description |
|---|---|
languages/javascript/custom/test/SessionFixation/SessionFixation.qlref |
Runs the custom session-fixation query. |
languages/javascript/custom/test/SessionFixation/SessionFixation.expected |
Records expected session-fixation alerts. |
languages/javascript/custom/test/SessionFixation/package.json |
Sets CommonJS fixture semantics. |
languages/javascript/custom/test/SessionFixation/nodegoat/user-dao.js |
Provides callback-based authentication fixtures. |
languages/javascript/custom/test/SessionFixation/nodegoat/server.js |
Connects session middleware and routes. |
languages/javascript/custom/test/SessionFixation/nodegoat/routes/session.js |
Covers direct session writes and regeneration. |
languages/javascript/custom/test/SessionFixation/nodegoat/routes/index.js |
Registers vulnerable and safe login routes. |
languages/javascript/custom/test/SessionFixation/goof/routes.js |
Covers session writes and regeneration in helpers. |
languages/javascript/custom/test/SessionFixation/goof/app.js |
Registers helper-based login fixtures. |
languages/javascript/custom/test/RateLimitSpoofableKeyTrustedProxy/RateLimitSpoofableKey.qlref |
Runs the spoofable-key query. |
languages/javascript/custom/test/RateLimitSpoofableKeyTrustedProxy/RateLimitSpoofableKey.expected |
Records the raw-header alert. |
languages/javascript/custom/test/RateLimitSpoofableKeyTrustedProxy/package.json |
Sets CommonJS fixture semantics. |
languages/javascript/custom/test/RateLimitSpoofableKeyTrustedProxy/app.js |
Covers fixed-hop trust and header casing. |
languages/javascript/custom/test/RateLimitSpoofableKey/server.ts |
Covers trust-all settings and nested routers. |
languages/javascript/custom/test/RateLimitSpoofableKey/RateLimitSpoofableKey.qlref |
Runs the spoofable-key query. |
languages/javascript/custom/test/RateLimitSpoofableKey/RateLimitSpoofableKey.expected |
Records alerts and data-flow paths. |
languages/javascript/custom/test/RateLimitSpoofableKey/package.json |
Sets CommonJS fixture semantics. |
languages/javascript/custom/test/RateLimitSpoofableKey/other-app.js |
Adds a separate non-trusting application. |
languages/javascript/custom/test/RateLimitSpoofableKey/limiters.js |
Covers limiter APIs, helpers, and safe keys. |
languages/javascript/custom/test/qlpack.yml |
Adds stock queries as a test dependency. |
languages/javascript/custom/test/MissingRateLimiting/package.json |
Sets CommonJS fixture semantics. |
languages/javascript/custom/test/MissingRateLimiting/nodegoat/user-dao.js |
Provides database-backed login validation. |
languages/javascript/custom/test/MissingRateLimiting/nodegoat/server.js |
Wires the NodeGoat-style application. |
languages/javascript/custom/test/MissingRateLimiting/nodegoat/routes/session.js |
Provides constructor-defined authentication handlers. |
languages/javascript/custom/test/MissingRateLimiting/nodegoat/routes/index.js |
Registers an unthrottled login route. |
languages/javascript/custom/test/MissingRateLimiting/MissingRateLimiting.qlref |
Runs the stock missing-rate-limiting query. |
languages/javascript/custom/test/MissingRateLimiting/MissingRateLimiting.expected |
Records three stock-query alerts. |
languages/javascript/custom/test/MissingRateLimiting/goof/routes.js |
Provides database-backed administrator login. |
languages/javascript/custom/test/MissingRateLimiting/goof/mongoose-db.js |
Defines the authentication database model. |
languages/javascript/custom/test/MissingRateLimiting/goof/app.js |
Compares throttled and unthrottled login routes. |
languages/javascript/custom/test/MissingRateLimiting/goatlin/routes/accounts.js |
Compares throttled and unthrottled authentication middleware. |
languages/javascript/custom/test/MissingRateLimiting/goatlin/models/account.js |
Defines the account lookup model. |
languages/javascript/custom/test/MissingRateLimiting/goatlin/middleware/auth.js |
Provides Basic authentication with database access. |
languages/javascript/custom/test/MissingRateLimiting/goatlin/app.js |
Mounts the account router. |
languages/javascript/custom/src/SessionFixation/SessionFixation.ql |
Tracks session objects across function calls. |
languages/javascript/custom/src/SessionFixation/SessionFixation.qhelp |
Documents session-fixation detection and remediation. |
languages/javascript/custom/src/SessionFixation/examples/SessionFixationGood.js |
Demonstrates regeneration before authentication writes. |
languages/javascript/custom/src/SessionFixation/examples/SessionFixationBad.js |
Demonstrates session reuse through a helper. |
languages/javascript/custom/src/RateLimitSpoofableKey/RateLimitSpoofableKey.ql |
Detects spoofable values flowing into limiter keys. |
languages/javascript/custom/src/RateLimitSpoofableKey/RateLimitSpoofableKey.qhelp |
Explains spoofable keys and proxy configuration. |
languages/javascript/custom/src/RateLimitSpoofableKey/examples/RateLimitSpoofableKeyGood.js |
Demonstrates a fixed-hop proxy configuration. |
languages/javascript/custom/src/RateLimitSpoofableKey/examples/RateLimitSpoofableKeyBad.js |
Demonstrates a client-controlled limiter key. |
languages/javascript/custom/src/change-notes/2026-10-31-session-fixation-rate-limit-key.md |
Summarizes both query additions. |
Review effort: Balanced
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
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.

📝 Query Update
languages/javascript/custom/src/SessionFixation/SessionFixation.ql(custom copy of the stockjs/session-fixation); new:languages/javascript/custom/src/RateLimitSpoofableKey/RateLimitSpoofableKey.ql(js/rate-limit-spoofable-key)🎯 Changes
What Changed
I rebuilt each of the 6 linked findings from the real source files and ran the shipped queries on them first. Only 2 were actual misses:
js/session-fixation. That query is only insecurity-extended, not the default suite.req.sessionis passed to a helper, and the helper does the writejs/session-fixationjs/missing-rate-limiting(default suite). The alert sits on the route registration, not on the handler.js/session-fixation(custom copy, same id)req.sessioninto other functions it is passed to, so both a session write and aregeneratecall inside a helper are found. Otherwise the logic matches the stock query.js/rate-limit-spoofable-key(new, path-problem)express-rate-limitandexpress-slow-downlimiters created withrateLimit(...),new RateLimit(...)orslowDown(...).keyGenerator(also followed into helper functions):x-forwarded-for,x-real-ip,forwarded,cf-connecting-ip, …) read viareq.headers[...],req.get(...)orreq.header(...);req.ipandreq.ips, only when the app that installs the limiter (or a parent app of the router that does) callsapp.enable('trust proxy')orset('trust proxy', true).keyGenerator.req.headers[...]is matched only by its lower-case name. Node lower-cases header keys, soheaders['X-Forwarded-For']is alwaysundefinedand is not reported.MissingRateLimiting/,SessionFixation/,RateLimitSpoofableKey/andRateLimitSpoofableKeyTrustedProxy/, each with safe counterparts that must not alert. The test pack now depends oncodeql/javascript-queriesso the stock query can be tested directly..qhelpwith good and bad examples for both queries, plus a change note.Why This Change
The AI scan reported these 6 findings and the default-setup scan did not. The point was to separate real query gaps from cases the stock queries already report, then close the real gaps.
Impact
js/session-fixation: more true positives on login routes that pass the session to a helper.keyGenerator.🔍 Before vs. After
Previous Behavior
New Behavior
app.post('/login', routes.loginHandler). Not reported when the helper callssession.regenerate(...).keyGeneratorreturn. The alert points atip: theX-Forwarded-Forlookup is alwaysundefined, so the key isreq.ip, which comes from the client'sX-Forwarded-Forbecause the app trusts every proxy.req.ipwithset('trust proxy', 1);req.ipin a different app with notrust proxysetting;x-api-key;req.socket.remoteAddress;🧪 Testing
📊 Impact Analysis
js/session-fixationreports everything the stock query reports, plus the new cases.js/rate-limit-spoofable-key, which is why its precision ismedium:X-Real-IPand makes it trustworthy.keyGenerator) are not checked.📋 Checklist
🔗 References