Skip to content

JS: Model AWS Lambda event parameters from @types/aws-lambda as remote sources - #23192

Open
ebickle wants to merge 1 commit into
github:mainfrom
ebickle:js/serverless-aws-lambda-types
Open

ebickle wants to merge 1 commit into
github:mainfrom
ebickle:js/serverless-aws-lambda-types

Conversation

@ebickle

@ebickle ebickle commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Treat the event parameter of an exported function as a remote flow source when its type comes from @types/aws-lambda. This provides robust coverage for AWS Lambda handler functions when TypeScript is used. Unlike the existing CodeQL coverage for serverless functions, this approach does not require any infrastructure-as-code files in the same repository.

Covered scenarios

The following usage patterns are supported:

  • untyped handler functions with a typed event
  • typed handler functions with an untyped event.

Extensibility using Models as Data (MaD) is supported using the new aws-lambda.Event and aws-lambda.Handler type models.

Not covered

  • Handlers for events that AWS generates itself, such as ScheduledEvent, are not included. This change focuses on events that are HTTP-exposed or involve externally generated data (S3, SQS, etc).
  • Handlers wrapped in a call, such as export const handler = middy(async (event: ...) => ...), because the function is not itself exported. Support for middleware frameworks such as Middy should be modeled independently.
  • Handler<TEvent> and plain Handler, because the type does not name the event.

…e sources

Treat the event parameter of an exported function as a remote flow source
when its type comes from `@types/aws-lambda`.

Supports both untyped handler functions with a typed event and typed handler functions with an untyped event.

The event and handler types defined in `aws-lambda.Event` and
`aws-lambda.Handler` type models in `ext/aws-lambda.model.json`, so they can
be extended using Models as Data.

Events that AWS generates itself, such as `ScheduledEvent`, are not included.
@ebickle
ebickle requested a review from a team as a code owner November 20, 2026 21:50
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 21:50

Copilot AI left a comment

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.

🟡 Changes recommended

Unresolved Lambda modeling defects miss typed exported aliases and deep-object security flows while incorrectly marking generic Handler event parameters and untyped helper parameters as remote sources.

4 open issues
What changed in this PR

This PR adds type-based AWS Lambda source modeling to JavaScript/TypeScript CodeQL analysis. It recognizes exported handlers using @types/aws-lambda without requiring infrastructure-as-code files.

Changes:

  • Treats event parameters as remote sources based on event or handler type annotations.
  • Adds extensible aws-lambda.Event and aws-lambda.Handler type models.
  • Adds positive and negative test fixtures and documents the analysis change.
File Description
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​test.ql Queries remote flow sources.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​test.expected Records expected source locations.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​lookalikeTypes.ts Defines unrelated lookalike types.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​lookalikes.ts Checks exclusion of unrelated same-name types.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​handlers.ts Covers typed handlers and export restrictions.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​events.ts Covers external events and excluded event types.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​cloudFront.ts Covers CloudFront event and handler types.
javascript/​ql/​test/​library-tests/​frameworks/​AwsLambda/​apiGateway.ts Covers API Gateway variants and event subtypes.
javascript/​ql/​lib/​semmle/​javascript/​frameworks/​AwsLambda.qll Identifies exported handlers and event sources.
javascript/​ql/​lib/​javascript.qll Imports the new Lambda framework model.
javascript/​ql/​lib/​ext/​aws-lambda.model.json Defines event and handler type mappings.
javascript/​ql/​lib/​change-notes/​2026-11-20-serverless-aws-lambda-types.md Documents coverage and model extensibility.

Review effort: Max (adaptive)

["aws-lambda.Event", "aws-lambda", "Member[SNSEvent].Instance"],
["aws-lambda.Event", "aws-lambda", "Member[SQSEvent].Instance"],
// API Gateway REST (v1), HTTP (v2), WebSocket, and authorizer handlers.
["aws-lambda.Handler", "aws-lambda", "Member[APIGatewayAuthorizerHandler].Instance"],
this = any(Module m).getAnExportedValue(_).getAFunctionValue() and
(
this.getParameter(0) =
ModelOutput::getATypeNode("aws-lambda.Event").getAValueReachableFromSource()
ModelOutput::getATypeNode("aws-lambda.Event").getAValueReachableFromSource()
or
exists(VariableDeclarator decl |
this = decl.getInit().flow() and
}

/** A source for the `event` parameter of an AWS Lambda handler. */
private class HandlerEventSource extends RemoteFlowSource {

This branch has not been deployed

No deployments
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