Skip to content

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

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

ebickle wants to merge 4 commits 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.
  • EventBridgeEvent.detail and AppSyncResolverEvent.arguments aren't additionally marked as deep user-controlled objects.

…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)

Add TaintedObject sources for EventBridge `detail` and AppSync `arguments`, rename the handler model to `aws-lambda.EventFunctionHandler`, and match event parameters by type directly.

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

The deep-object event sources lack a restriction to the first parameter of an EventFunctionHandler, allowing trusted events in private helpers to produce false-positive taint flows.

1 open issue
4 resolved since last review

Review effort: Balanced (adaptive)

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

The AWS Lambda models miss valid handler declarations, helper-forwarded payload reads, and AppSync batch arguments, leaving gaps in remote-source and prototype-pollution detection.

1 open issue
4 previously missed issues

In code that hasn't changed since last review

Medium severity Model AppSync batch resolver events and handlers

javascript/​ql/​lib/​ext/​aws-lambda.model.json:73

AppSyncBatchResolverHandler is modeled only as a generic handler, so each event element's arguments never becomes a deeply tainted source, leaving batch resolvers without prototype-pollution coverage. An exported function with a parameter typed as AppSyncResolverEvent<Args>[] is also missed entirely because the parameter is an array, not a modeled event (AwsLambda.qll:14). Add batch-event and batch-handler models that recognize the array and create deep-object sources for its elements' arguments, with tests for both declaration forms.

Medium severity Use the lighter tainted-object customizations import

javascript/​ql/​lib/​semmle/​javascript/​frameworks/​AwsLambda.qll:6

Other library code that only needs the TaintedObject::Source class (e.g. SecondOrderCommandInjectionCustomizations.qll, TemplateObjectInjectionCustomizations.qll, DeepObjectResourceExhaustionCustomizations.qll) imports semmle.javascript.security.TaintedObjectCustomizations, which is documented as providing access to the tainted-object definitions "without materializing that flow label". TaintedObject.qll additionally pulls in the flow steps, sanitizer guards and the deprecated materialized label. Since AwsLambda.qll is imported by javascript.qll, it is loaded by every JavaScript query, so it should use the lighter import. The TaintedObject::Source references below resolve the same way with it.

Medium severity Recognize annotated handlers assigned after declaration

javascript/​ql/​lib/​semmle/​javascript/​frameworks/​AwsLambda.qll:19

This only examines the variable initializer, so a typed handler assigned later is missed. For example, let handler: SQSHandler; handler = async (event) => { /* use event */ }; export { handler }; exports a typed Lambda handler, but decl.getInit() has no result and the unannotated parameter cannot match the event-type branch either. Please consider all expressions assigned to the annotated variable (for example via Variable.getAnAssignedExpr()), and cover a separate assignment in the handler tests.

Medium severity Recognize handler-typed exported expressions

javascript/​ql/​lib/​semmle/​javascript/​frameworks/​AwsLambda.qll:19

This only recognizes handler types attached to variable declarators, so a valid default export such as export default (async (event) => { ... }) satisfies APIGatewayProxyHandler is missed: the event is unannotated and there is no declarator to match. Recognize handler-typed exported expressions (including satisfies and type assertions) as well, so these handlers become remote sources.

1 resolved since last review

Review effort: Max (adaptive)

@ebickle

ebickle commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

I can't find any precedent for a RemoteFlowSource that isn't a tainted object, but contains a child field that is a tainted object. Resolving this cleanly would likely require core library changes in CodeQL and support from the GitHub team.

Recommend that we proceed without the tainted object tracking on AppSyncResolverEvent and EventBridgeEvent, which can be added in a subsequent pull request if needed. Adding the TypeScript AWS Lambda support that this PR provides provides broad coverage as it is.

Besides, there are some other scenarios that can be added in subsequent pull requests - HTTP-specific request handling being an example. Some of that functionality, redirects in particular, also would require core framework changes.

Drop the EventBridge/AppSync deep-object sources and recognize handlers typed via satisfies/as or assigned after declaration.

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.

🔵 Needs a closer look

The EventBridge handler model omits deep object taint for producer-controlled payloads, which can cause NoSQL injection and prototype pollution vulnerabilities to go undetected.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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