Skip to content

Go: Add flow sources for AWS Lambda function handlers #15373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

atorralba
Copy link
Contributor

This PR adds support for flow sources in AWS Lambda function handlers.

Comment on lines 28 to 32
this = any(Method m | m.implements(awsLambdaPkg(), "Handler", "Invoke")).getFuncDecl()
or
exists(ConversionExpr ce |
ce.getTypeExpr().getType() instanceof HandlerImpl and
this = ce.getOperand().(FunctionName).getTarget().getFuncDecl()
Copy link
Contributor Author

@atorralba atorralba Jan 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that not requiring these two ways of declaring a handler to be used in a Start* or NewHandler* call to consider their parameters as sources is intended.

Firstly, because there are many ways of passing such a function/struct reference as argument of those calls (a variable, a conversion expression, a struct creation...) and we could have FNs if we tried to model them all, in addition to overcomplicating the models by having to use data flow analysis.

And secondly, because if a function is used in the ways modeled here, even if we don't enforce their use in a Start* or NewHandler* call, chances are that function is indeed going to be used as a lambda handler (and even if it isn't currently, the intention to do it is there, so we should preemptively alert anyway).

@atorralba atorralba force-pushed the atorralba/go/aws-lambda-sources branch from 51a10de to 1d7dbec Compare January 18, 2024 14:17
LambdaInput() {
exists(Parameter p | p = this.asParameter() |
p = any(HandlerFunction hf).getAParameter() and
not p.getType().hasQualifiedName("context", "Context") and
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I'm not considering any part of the Context as tainted (a more thorough analysis in the future may be worthwhile to make sure).

@atorralba
Copy link
Contributor Author

DCA looks uneventful as expected.

@atorralba atorralba marked this pull request as ready for review January 18, 2024 16:31
@atorralba atorralba requested a review from a team as a code owner January 18, 2024 16:31
@atorralba atorralba requested a review from smowton January 18, 2024 16:32
]) and
handlerArgPos = 0
or
this.hasQualifiedName(awsLambdaPkg(), "StartHandlerWithContext") and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also StartWithContext

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, added here.

atorralba and others added 2 commits January 19, 2024 09:22
Co-authored-by: Chris Smowton <smowton@github.com>
Co-authored-by: Chris Smowton <smowton@github.com>
Comment on lines 30 to 32
exists(ConversionExpr ce |
ce.getTypeExpr().getType() instanceof HandlerImpl and
this = ce.getOperand().(FunctionName).getTarget().getFuncDecl()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exists(ConversionExpr ce |
ce.getTypeExpr().getType() instanceof HandlerImpl and
this = ce.getOperand().(FunctionName).getTarget().getFuncDecl()
exists(TypeCastNode typeCast |
typeCast.getResultType() instanceof HandlerImpl and
this.(FuncDecl).getFunction().getARead() = typeCast.getOperand()

Sorry, should have picked this one up at the same time as the above. Also are there any tests for this path at the moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Also are there any tests for this path at the moment?

Yes, the ones using MyHandlerFunc, e.g.

lambda.StartHandler(MyHandlerFunc(Handler9))

Co-authored-by: Chris Smowton <smowton@github.com>
@atorralba atorralba force-pushed the atorralba/go/aws-lambda-sources branch from 73c0a38 to 8d6aa28 Compare January 19, 2024 09:48
@atorralba atorralba merged commit 7e7175f into github:main Jan 19, 2024
@atorralba atorralba deleted the atorralba/go/aws-lambda-sources branch January 19, 2024 10:21
smowton added a commit that referenced this pull request Jan 19, 2024
JS/TS support is old; noting for symmetry with advertised support in Python. Golang support is new as of #15373
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