Skip to content

Commit

Permalink
fix counting safe function call depth
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 26, 2024
1 parent 50e7201 commit 9e16139
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 3 additions & 5 deletions expr_insecure.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ func (u *UntrustedInputChecker) OnVisitNodeEnter(n ExprNode) {
func (u *UntrustedInputChecker) OnVisitNodeLeave(n ExprNode) {
// Skip unsafe checks if we are inside of safe function call expression
if u.safeCalls > 0 {
if f, ok := n.(*FuncCallNode); ok && isSafeFuncCall(f) {
u.safeCalls--
}
return
}

Expand All @@ -323,11 +326,6 @@ func (u *UntrustedInputChecker) OnVisitNodeLeave(n ExprNode) {
u.onIndexAccess()
case *ArrayDerefNode:
u.onObjectFilter()
case *FuncCallNode:
if isSafeFuncCall(n) {
u.safeCalls--
}
u.end()
default:
u.end()
}
Expand Down
3 changes: 3 additions & 0 deletions expr_insecure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func testRunTrustedInputsCheckerForNode(t *testing.T, c *UntrustedInputChecker,
}
})
c.OnVisitEnd()
if c.safeCalls != 0 {
t.Fatalf("%q safe calls counter is not zero: %d", input, c.safeCalls)
}
}

func TestExprInsecureDetectUntrustedValue(t *testing.T) {
Expand Down

0 comments on commit 9e16139

Please sign in to comment.