-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Go: Add flow sources for AWS Lambda function handlers #15373
Conversation
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() |
There was a problem hiding this comment.
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).
51a10de
to
1d7dbec
Compare
LambdaInput() { | ||
exists(Parameter p | p = this.asParameter() | | ||
p = any(HandlerFunction hf).getAParameter() and | ||
not p.getType().hasQualifiedName("context", "Context") and |
There was a problem hiding this comment.
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).
DCA looks uneventful as expected. |
]) and | ||
handlerArgPos = 0 | ||
or | ||
this.hasQualifiedName(awsLambdaPkg(), "StartHandlerWithContext") and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also StartWithContext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, added here.
Co-authored-by: Chris Smowton <smowton@github.com>
Co-authored-by: Chris Smowton <smowton@github.com>
exists(ConversionExpr ce | | ||
ce.getTypeExpr().getType() instanceof HandlerImpl and | ||
this = ce.getOperand().(FunctionName).getTarget().getFuncDecl() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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>
73c0a38
to
8d6aa28
Compare
JS/TS support is old; noting for symmetry with advertised support in Python. Golang support is new as of #15373
This PR adds support for flow sources in AWS Lambda function handlers.