You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS: Model AWS Lambda event parameters from @types/aws-lambda as remote sources - #23192
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.
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.
Add TaintedObject sources for EventBridge `detail` and AppSync `arguments`, rename the handler model to `aws-lambda.EventFunctionHandler`, and match event parameters by type directly.
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.
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.
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.
Use the lighter tainted-object customizations import
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.
Recognize annotated handlers assigned after declaration
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.
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.
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.
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.
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
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.EventBridgeEvent.detailandAppSyncResolverEvent.argumentsaren't additionally marked as deep user-controlled objects.