Repository navigation
Conversation
…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.
Contributor
There was a problem hiding this comment.
🟡 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.Eventandaws-lambda.Handlertype 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
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.

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:
Extensibility using Models as Data (MaD) is supported using the new
aws-lambda.Eventandaws-lambda.Handlertype models.Not covered
ScheduledEvent, are not included. This change focuses on events that are HTTP-exposed or involve externally generated data (S3, SQS, etc).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 plainHandler, because the type does not name the event.