JS: Add models-as-data for openapi-backend - #22715
Open
anttiviljami wants to merge 2 commits into
Open
anttiviljami wants to merge 2 commits into
anttiviljami wants to merge 2 commits into
Conversation
Mark `context.request` in openapi-backend operation handlers, security handlers, lifecycle handlers and `validate` predicates as a remote flow source, covering handlers passed to the constructor, `register()`, `registerHandler()`, `registerSecurityHandler()`, the awaited result of `init()`, and TypeScript handlers typed with `Context`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
anttiviljami
force-pushed
the
js/openapi-backend
branch
from
September 30, 2026 15:46
0a773bf to
9522ce7
Compare
anttiviljami
marked this pull request as ready for review
September 30, 2026 15:46
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new validate and registerHandler model paths lack direct regression coverage.
Review effort: Balanced
Findings: 2
Open (2)
What changed in this PR
Adds models-as-data support for treating openapi-backend request contexts as remote input sources.
Changes:
- Models constructors, initialization, handler registration, and typed contexts.
- Adds SQL-injection fixtures and generated expectations.
- Documents the analysis improvement.
| File | Description |
|---|---|
javascript/ql/lib/ext/openapi-backend.model.yml |
Defines framework type and source models. |
javascript/ql/lib/change-notes/2026-09-30-openapi-backend.md |
Adds the library change note. |
javascript/ql/test/query-tests/Security/CWE-089/untyped/openapi-backend.js |
Tests JavaScript handler flows. |
javascript/ql/test/query-tests/Security/CWE-089/untyped/openapi-backend-typed.ts |
Tests typed context flow. |
javascript/ql/test/query-tests/Security/CWE-089/untyped/DatabaseAccesses.expected |
Updates generated database-access results. |
javascript/ql/test/query-tests/Security/CWE-089/untyped/SqlInjection.expected |
Updates generated SQL-injection results. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.

Added models-as-data support for
openapi-backend, a framework-agnostic Node.js library that routes, validates and authenticates requests from an OpenAPI definition.Background
I maintain openapi-backend as part of openapi-stack.
openapistack/openapi-backend-modelsfrom openapi-backend-codeql, next to openapi-backend-specific queries. Its CI checks this same model against CodeQL's built-injs/sql-injectionquery, including a control run that confirms the query misses the flow without it.Upstreaming it means every CodeQL user gets this coverage without extra configuration.
The problem
openapi-backend parses the incoming request itself and passes handlers a context object
c, with the request data onc.request(params,query,headers,cookies,requestBody, ...). That object is built inside the library, so no existing source model covers it, and flows like this aren't found:The model
c.requestbecomes aremotesource in every handler openapi-backend calls with a context: operation handlers, security handlers, lifecycle handlers andvalidatepredicates. That covers handlers registered:handlers,securityHandlers,validate)register(name, fn),register({ ... }),registerHandler()andregisterSecurityHandler()init()(c: Context) => ...The type names follow the library's real exports (
OpenAPIBackend,Handler,Context), so TypeScript annotations match as described in customizing library models for JavaScript.Checklist
javascript/ql/lib/change-notes/(minorAnalysis, library pack)CWE-089/untypedSQL injection tests, using inline expectations, including a parameterised query that stays unflagged.expectedfiles generated withcodeql test run, purely additiveThanks to @sylwia-budzynska from GitHub Security Lab for advising on this contribution!