Skip to content

Commit 5675df8

Browse files
authored
Merge pull request #15054 from owen-mc/go/find-more-callees-for-captured-variables
Go: Also follow jump steps when looking for a callee source
2 parents 609f92c + 0fb58ca commit 5675df8

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* `CallNode::getACallee` and related predicates now recognise more callees accessed via a function variable, in particular when the callee is stored into a global variable or is captured by an anonymous function. This may lead to new alerts where data-flow into such a callee is relevant.

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ module Public {
473473
private DataFlow::Node getACalleeSource(DataFlow::CallNode cn) {
474474
result = cn.getCalleeNode() or
475475
basicLocalFlowStep(result, getACalleeSource(cn)) or
476+
jumpStep(result, getACalleeSource(cn)) or
476477
result.asExpr() = getACalleeSource(cn).asExpr().(GenericFunctionInstantiationExpr).getBase()
477478
}
478479

go/ql/test/library-tests/semmle/go/frameworks/Twirp/RequestForgery.expected

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ edges
33
| client/main.go:16:35:16:78 | &... | server/main.go:19:56:19:61 | definition of params |
44
| rpc/notes/service.twirp.go:473:6:473:13 | definition of typedReq | rpc/notes/service.twirp.go:477:44:477:51 | typedReq |
55
| rpc/notes/service.twirp.go:477:44:477:51 | typedReq | server/main.go:19:56:19:61 | definition of params |
6+
| rpc/notes/service.twirp.go:493:2:493:2 | capture variable reqContent | rpc/notes/service.twirp.go:495:35:495:44 | reqContent |
7+
| rpc/notes/service.twirp.go:495:35:495:44 | reqContent | server/main.go:19:56:19:61 | definition of params |
8+
| rpc/notes/service.twirp.go:538:2:538:33 | ... := ...[0] | rpc/notes/service.twirp.go:544:27:544:29 | buf |
9+
| rpc/notes/service.twirp.go:538:25:538:32 | selection of Body | rpc/notes/service.twirp.go:538:2:538:33 | ... := ...[0] |
10+
| rpc/notes/service.twirp.go:543:2:543:11 | definition of reqContent | rpc/notes/service.twirp.go:574:2:574:2 | capture variable reqContent |
11+
| rpc/notes/service.twirp.go:544:27:544:29 | buf | rpc/notes/service.twirp.go:543:2:543:11 | definition of reqContent |
612
| rpc/notes/service.twirp.go:554:6:554:13 | definition of typedReq | rpc/notes/service.twirp.go:558:44:558:51 | typedReq |
713
| rpc/notes/service.twirp.go:558:44:558:51 | typedReq | server/main.go:19:56:19:61 | definition of params |
14+
| rpc/notes/service.twirp.go:574:2:574:2 | capture variable reqContent | rpc/notes/service.twirp.go:576:35:576:44 | reqContent |
15+
| rpc/notes/service.twirp.go:576:35:576:44 | reqContent | server/main.go:19:56:19:61 | definition of params |
816
| server/main.go:19:56:19:61 | definition of params | client/main.go:16:35:16:78 | &... |
917
| server/main.go:19:56:19:61 | definition of params | rpc/notes/service.twirp.go:473:6:473:13 | definition of typedReq |
18+
| server/main.go:19:56:19:61 | definition of params | rpc/notes/service.twirp.go:493:2:493:2 | capture variable reqContent |
1019
| server/main.go:19:56:19:61 | definition of params | rpc/notes/service.twirp.go:554:6:554:13 | definition of typedReq |
20+
| server/main.go:19:56:19:61 | definition of params | rpc/notes/service.twirp.go:574:2:574:2 | capture variable reqContent |
1121
| server/main.go:19:56:19:61 | definition of params | server/main.go:19:56:19:61 | definition of params |
1222
| server/main.go:19:56:19:61 | definition of params | server/main.go:19:56:19:61 | definition of params |
1323
| server/main.go:19:56:19:61 | definition of params | server/main.go:30:38:30:48 | selection of Text |
@@ -16,11 +26,20 @@ nodes
1626
| client/main.go:16:35:16:78 | &... | semmle.label | &... |
1727
| rpc/notes/service.twirp.go:473:6:473:13 | definition of typedReq | semmle.label | definition of typedReq |
1828
| rpc/notes/service.twirp.go:477:44:477:51 | typedReq | semmle.label | typedReq |
29+
| rpc/notes/service.twirp.go:493:2:493:2 | capture variable reqContent | semmle.label | capture variable reqContent |
30+
| rpc/notes/service.twirp.go:495:35:495:44 | reqContent | semmle.label | reqContent |
31+
| rpc/notes/service.twirp.go:538:2:538:33 | ... := ...[0] | semmle.label | ... := ...[0] |
32+
| rpc/notes/service.twirp.go:538:25:538:32 | selection of Body | semmle.label | selection of Body |
33+
| rpc/notes/service.twirp.go:543:2:543:11 | definition of reqContent | semmle.label | definition of reqContent |
34+
| rpc/notes/service.twirp.go:544:27:544:29 | buf | semmle.label | buf |
1935
| rpc/notes/service.twirp.go:554:6:554:13 | definition of typedReq | semmle.label | definition of typedReq |
2036
| rpc/notes/service.twirp.go:558:44:558:51 | typedReq | semmle.label | typedReq |
37+
| rpc/notes/service.twirp.go:574:2:574:2 | capture variable reqContent | semmle.label | capture variable reqContent |
38+
| rpc/notes/service.twirp.go:576:35:576:44 | reqContent | semmle.label | reqContent |
2139
| server/main.go:19:56:19:61 | definition of params | semmle.label | definition of params |
2240
| server/main.go:19:56:19:61 | definition of params | semmle.label | definition of params |
2341
| server/main.go:30:38:30:48 | selection of Text | semmle.label | selection of Text |
2442
subpaths
2543
#select
44+
| server/main.go:30:38:30:48 | selection of Text | rpc/notes/service.twirp.go:538:25:538:32 | selection of Body | server/main.go:30:38:30:48 | selection of Text | The $@ of this request depends on a $@. | server/main.go:30:38:30:48 | selection of Text | URL | rpc/notes/service.twirp.go:538:25:538:32 | selection of Body | user-provided value |
2645
| server/main.go:30:38:30:48 | selection of Text | server/main.go:19:56:19:61 | definition of params | server/main.go:30:38:30:48 | selection of Text | The $@ of this request depends on a $@. | server/main.go:30:38:30:48 | selection of Text | URL | server/main.go:19:56:19:61 | definition of params | user-provided value |

0 commit comments

Comments
 (0)