Skip to content

[Query Update]: CWE-307, CWE-384 MEDIUM - JavaScript: extend login rate limiting and session fixation coverage (js/session-fixation, js/user-controlled-bypass, js/missing-r) #358

Open

Description

@felickz

Query File Path

js/session-fixation, js/user-controlled-bypass, js/missing-rate-limiting, js/missing-rate-limiting

Update Type

Enhanced detection coverage

Issue Description

AI Scan reported 6 medium-severity CWE-307, CWE-384 (auth rate limit session fixation) finding(s) in JavaScript public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: query-logic, scope-condition, query-absent. Existing queries considered: js/session-fixation, js/user-controlled-bypass, js/missing-rate-limiting, js/missing-rate-limiting.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • Shipped js/session-fixation looks for a route path containing 'login', a req.session write, and no regenerate call. This handler has exactly those semantics, so the miss is in route/handler recognition or local flow logic.
  • The nearby shipped missing-rate-limiting alerts concern different routes. This route has a limiter, but its key is attacker-controlled X-Forwarded-For under trust-proxy; detecting the bypass needs query logic linking limiter configuration to an untrusted key.
  • Login handler without rate limiting; existing query targets expensive handlers only.
  • Login sets session state without regenerating session id; no JS session-fixation query.

Linked findings (gap-key: javascript/query-update/auth-rate-limit-session-fixation)

Repo CWE Severity AI scan alert Summary
NodeGoat CWE-384 medium https://github.com/codeql-forks-felickz/NodeGoat/security/code-scanning/27 The login handler assigns the authenticated user ID to the existing session instead of regenerating it. An attacker who obtains or fixes a victim's pre-login session ID can reuse that same ID after the victim authenticates and hijack the account.
juice-shop CWE-307 medium https://github.com/codeql-forks-felickz/juice-shop/security/code-scanning/118 The application trusts proxy headers globally and the reset-password limiter uses the raw attacker-controlled X-Forwarded-For header as its key. A client can rotate that header on each request to evade the per-IP limit and brute-force password-reset security answers.
Goatlin CWE-307 medium https://github.com/codeql-forks-felickz/Goatlin/security/code-scanning/16 Every protected API request performs an unrestricted email/password lookup, with no per-account or per-source attempt limit, delay, or lockout anywhere in the application. Attackers can repeatedly submit guessed Basic credentials—assisted by the registration endpoint's email enumeration signal—until a password is found. Add rate limiting and progressive account-level protections while avoiding denial-of-service-prone permanent lockouts.
NodeGoat CWE-307 medium https://github.com/codeql-forks-felickz/NodeGoat/security/code-scanning/39 The login handler performs authentication on every request with no per-account or per-source throttling, delay, or temporary lockout. Attackers can therefore automate password spraying and brute-force attacks, made more effective by the weak password policy and username enumeration. Add layered rate limiting and monitored, carefully bounded account backoff.
nodejs-goof CWE-384 medium https://github.com/codeql-forks-felickz/nodejs-goof/security/code-scanning/54 On successful login the handler only sets session.loggedIn = 1 on the existing session instead of calling req.session.regenerate(). An attacker who can set or learn a victim's connect.sid value before login (e.g. via a fixation vector) retains a session that becomes authenticated. The session is further weakened by a static, publicly known signing secret and a cookie configuration that does not set secure or sameSite.
nodejs-goof CWE-307 medium https://github.com/codeql-forks-felickz/nodejs-goof/security/code-scanning/48 The administrator login handler has no per-account or per-client throttling, delay, or lockout. A remote attacker can make unrestricted password attempts against a known username, enabling automated online brute-force and credential-stuffing attacks.

Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.

Handling decision

  • Type: Query Update
  • Decision: Update existing CodeQL queries. The queries named above already target this weakness class; the findings show missing flow steps, sinks, sources, barriers or scope handling. Extend the smallest existing query or model instead of adding a new query.
  • Recommended actions across the findings: extend-existing-query (5), write-new-query (1)

Patterns in this gap

  • missing-rate-limiting-login (3 findings), for example Goatlin packages/services/api/src/middleware/auth.js
  • query-logic (2 findings), for example NodeGoat app/routes/session.js
  • session-fixation (1 finding), for example nodejs-goof routes/index.js

Finding details

Each finding below has its own context so the agent can work from this issue alone.

1. NodeGoat app/routes/session.js:116 (CWE-384, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/NodeGoat/security/code-scanning/27
  • AI Scan message: The login handler assigns the authenticated user ID to the existing session instead of regenerating it. An attacker who obtains or fixes a victim's pre-login session ID can reuse that same ID after the victim authenticates and hijack the account.
  • Why CodeQL appears to miss it: query-logic: Shipped js/session-fixation looks for a route path containing 'login', a req.session write, and no regenerate call. This handler has exactly those semantics, so the miss is in route/handler recognition or local flow logic.
  • Existing CodeQL queries considered: js/session-fixation
  • Recommended action from the comparison: extend-existing-query (classification confidence: high)
2. juice-shop server.ts:365 (CWE-307, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/juice-shop/security/code-scanning/118
  • AI Scan message: The application trusts proxy headers globally and the reset-password limiter uses the raw attacker-controlled X-Forwarded-For header as its key. A client can rotate that header on each request to evade the per-IP limit and brute-force password-reset security answers.
  • Why CodeQL appears to miss it: query-logic: The nearby shipped missing-rate-limiting alerts concern different routes. This route has a limiter, but its key is attacker-controlled X-Forwarded-For under trust-proxy; detecting the bypass needs query logic linking limiter configuration to an untrusted key.
  • Existing CodeQL queries considered: js/user-controlled-bypass, js/missing-rate-limiting
  • Recommended action from the comparison: extend-existing-query (classification confidence: medium)
3. Goatlin packages/services/api/src/middleware/auth.js:16 (CWE-307, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/Goatlin/security/code-scanning/16
  • AI Scan message: Every protected API request performs an unrestricted email/password lookup, with no per-account or per-source attempt limit, delay, or lockout anywhere in the application. Attackers can repeatedly submit guessed Basic credentials—assisted by the registration endpoint's email enumeration signal—until a password is found. Add rate limiting and progressive account-level protections while avoiding denial-of-service-prone permanent lockouts.
  • Context for the agent: In Goatlin at packages/services/api/src/middleware/auth.js:16: Every protected API request performs an unrestricted email/password lookup, with no per-account or per-source attempt limit, delay, or lockout anywhere in the application. Attackers can repeatedly submit guessed Basic credentials—assisted by the registration e CodeQL would need an extension of the existing query (source/sink/sanitizer modelling) to flag this pattern.
  • Why CodeQL appears to miss it: scope-condition: Login handler without rate limiting; existing query targets expensive handlers only.
  • Existing CodeQL queries considered: js/missing-rate-limiting
  • Recommended action from the comparison: extend-existing-query (classification confidence: low)
4. NodeGoat app/routes/session.js:58 (CWE-307, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/NodeGoat/security/code-scanning/39
  • AI Scan message: The login handler performs authentication on every request with no per-account or per-source throttling, delay, or temporary lockout. Attackers can therefore automate password spraying and brute-force attacks, made more effective by the weak password policy and username enumeration. Add layered rate limiting and monitored, carefully bounded account backoff.
  • Context for the agent: In NodeGoat at app/routes/session.js:58: The login handler performs authentication on every request with no per-account or per-source throttling, delay, or temporary lockout. Attackers can therefore automate password spraying and brute-force attacks, made more effective by the weak password policy an CodeQL would need an extension of the existing query (source/sink/sanitizer modelling) to flag this pattern.
  • Why CodeQL appears to miss it: scope-condition: Login handler without rate limiting; existing query targets expensive handlers only.
  • Existing CodeQL queries considered: js/missing-rate-limiting
  • Recommended action from the comparison: extend-existing-query (classification confidence: low)
5. nodejs-goof routes/index.js:68 (CWE-384, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/nodejs-goof/security/code-scanning/54
  • AI Scan message: On successful login the handler only sets session.loggedIn = 1 on the existing session instead of calling req.session.regenerate(). An attacker who can set or learn a victim's connect.sid value before login (e.g. via a fixation vector) retains a session that becomes authenticated. The session is further weakened by a static, publicly known signing secret and a cookie configuration that does not set secure or sameSite.
  • Context for the agent: In nodejs-goof at routes/index.js:68: On successful login the handler only sets session.loggedIn = 1 on the existing session instead of calling req.session.regenerate(). An attacker who can set or learn a victim's connect.sid value before login (e.g. via a fixation vector) retains a session CodeQL would need a new query or sink coverage for this pattern.
  • Why CodeQL appears to miss it: query-absent: Login sets session state without regenerating session id; no JS session-fixation query.
  • Recommended action from the comparison: write-new-query (classification confidence: medium)
6. nodejs-goof routes/index.js:50 (CWE-307, medium)
  • AI Scan alert: https://github.com/codeql-forks-felickz/nodejs-goof/security/code-scanning/48
  • AI Scan message: The administrator login handler has no per-account or per-client throttling, delay, or lockout. A remote attacker can make unrestricted password attempts against a known username, enabling automated online brute-force and credential-stuffing attacks.
  • Context for the agent: In nodejs-goof at routes/index.js:50: The administrator login handler has no per-account or per-client throttling, delay, or lockout. A remote attacker can make unrestricted password attempts against a known username, enabling automated online brute-force and credential-stuffing attacks. CodeQL would need an extension of the existing query (source/sink/sanitizer modelling) to flag this pattern.
  • Why CodeQL appears to miss it: scope-condition: Login handler without rate limiting; existing query targets expensive handlers only.
  • Existing CodeQL queries considered: js/missing-rate-limiting
  • Recommended action from the comparison: extend-existing-query (classification confidence: low)

Proposed Solution

  1. Reproduce each linked finding with a minimal synthetic test case and confirm the baseline result.
  2. Identify the missing source, sink, summary or scope condition and extend the smallest model or query that fixes it.
  3. Add positive and negative tests and a change note.
  4. Check the false-positive rate on the other linked findings before widening.

Code Examples

See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.

Breaking Change?

No - backward compatible

References (Optional)

https://cwe.mitre.org/data/definitions/307.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    severity:medium
    on Oct 31, 2026
  2. added
    precision:medium
    tags:experimental
    on Nov 3, 2026
  3. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:medium Relies on heuristics or accepted over-approximation. Community Packs, always tags:experimental. tags:experimental Goes to Community Packs: performance, false-positive or synthetic-only concerns.

    Community Packs, experimental. Recommended for the Community Packs repository, not github/codeql. The issue is labeled tags:experimental for this.

    Separable piece. session handling patch to js/session-fixation, with real-project evidence. This part could be proposed to github/codeql on its own, see the split note below.

    Linked pull request: #367

    Why. Mixed PR. The session change adds req.session type tracking to a stock query (scratch run: stock reports 1 of 2 test routes, the copy both) but keeps its login-path heuristic and the stock id. The rate-limit query is new, relies on a fixed header list and the deployment's trust proxy setting, and falls back to any app in the database for unlinked limiters. Medium precision: Community Packs, experimental; the session patch could go upstream alone.

    Change New query
    Target Stock js/session-fixation (patched copy); new query for express-rate-limit keyGenerator keys
    Precision assessed medium (declared medium in the pull request). Session patch only adds type tracking but keeps the stock '%login%' route-path heuristic. Rate-limit query uses a fixed client-IP header list, a fallback to any app trusting all proxies when a limiter is unlinked, and ignores proxy deployment, so noticeable false positives are plausible.
    Real-world basis general. Public libraries: express, express-session, express-rate-limit and express-slow-down (keyGenerator, trust proxy). Query logic has no app-specific names; the patterns are only reduced from synthetic apps in tests.
    Stock overlap partial. Session part patches stock js/session-fixation (same id): scratch run, stock finds 1 of 2 test routes, the copy both. No stock query for spoofable rate-limit keys.
    Concerns, overlap and next steps

    False-positive concerns

    • A limiter keyed on cf-connecting-ip, x-real-ip or true-client-ip behind a CDN or proxy that sets the header is reported, though not spoofable there.
    • req.ip with trust proxy set to true is reported even when an edge proxy overwrites X-Forwarded-For.
    • A limiter that cannot be linked to an app is reported if any app in the database trusts all proxies.
    • Session: any req.session write in a route whose path contains 'login' counts as login (flash or return-to values, helpers).

    Performance concerns

    • sessionRef type-tracks req.session through calls for every Express route handler, not only login routes; cost not measured.

    Heuristics used

    • Route path must contain 'login' (kept from stock js/session-fixation)
    • Fixed list of ten client-IP header names treated as spoofable
    • Unlinked limiter falls back to any app in the database that trusts all proxies

    What an upstream change would look like. Community Packs: javascript/src/security/CWE-307/RateLimitSpoofableKey.ql with tests. The session patch could instead be a small PR to stock Security/CWE-384/SessionFixation.ql with tests and a change note; a Community Packs copy needs a distinct @id.

    Before opening an upstream pull request

    • Show a true positive on a real, non-synthetic project revision for the rate-limit query
    • Drop or justify CDN client-IP headers (cf-connecting-ip, fastly-client-ip, true-client-ip) as spoofable
    • Decide on the fallback that treats any trusting app in the database as the limiter's app
    • Give the session variant a distinct @id if kept as a copy, or propose it against the stock query
    • Measure the cost of the req.session type tracking on a large database

    Split note. Two parts. The session change patches a stock query (type-tracks req.session into helpers) and is the better candidate for github/codeql on its own, with real-project evidence. The rate-limit query is new and medium precision, so Community Packs.

    Change from the initial guess. When this issue was opened the coarse destination guess was github/codeql. Reading the actual pull request changed it to Community Packs.

    This is a recommendation only. A human reviews it before any pull request is opened against github/codeql or the Community Packs repository.

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

Metadata

Metadata

Labels

CWE-307CWE-384enhancementprecision:mediumquery-updateseverity:mediumtags:experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions