Skip to content
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

fix: don't use asterisk for non-literal strings #1320

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,12 @@ children:
- node: 57
content: s2 += args[0]
data:
value: hey *
value: hey
isliteral: false
- node: 67
content: s2 += " there"
data:
value: hey * there
value: hey there
isliteral: false
- node: 38
content: Greeting + "!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ children:
- node: 19
content: x += name
data:
value: ab*
value: ab
isliteral: false
- node: 30
content: y += "c"
data:
value: '*c'
value: �c
isliteral: false
- node: 6
content: '"a"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ children:
- node: 2
content: '"a" + x'
data:
value: a*
value: a
isliteral: false
- node: 10
content: '`${x} b`'
data:
value: '* b'
value: � b
isliteral: false
- node: 3
content: '"a"'
Expand Down
2 changes: 1 addition & 1 deletion internal/languages/javascript/detectors/string/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func handleTemplateString(node *tree.Node, detectorContext types.Context) ([]int
}

if childValue == "" && !childIsLiteral {
childValue = "*"
childValue = common.NonLiteralValue
}

text += childValue
Expand Down
10 changes: 5 additions & 5 deletions internal/languages/php/detectors/.snapshots/TestPHPString-string
Original file line number Diff line number Diff line change
Expand Up @@ -533,22 +533,22 @@ children:
- node: 52
content: $s .= "!!"
data:
value: '*!!!'
value: !!!
isliteral: false
- node: 74
content: $s2 .= $args[0]
data:
value: hey *
value: hey
isliteral: false
- node: 88
content: $s2 .= " there"
data:
value: hey * there
value: hey there
isliteral: false
- node: 39
content: self::Greeting . "!"
data:
value: '*!'
value: �!
isliteral: false
- node: 57
content: '"!!"'
Expand All @@ -568,7 +568,7 @@ children:
- node: 104
content: '"foo ''{$s2}'' bar"'
data:
value: foo 'hey * there' bar
value: foo 'hey there' bar
isliteral: false
- node: 46
content: '"!"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ children:
- node: 15
content: x += name
data:
value: ab*
value: ab
isliteral: false
- node: 23
content: y += "c"
data:
value: '*c'
value: �c
isliteral: false
- node: 4
content: '"a"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ children:
- node: 1
content: '"a" + x'
data:
value: a*
value: a
isliteral: false
- node: 8
content: '"#{x} b"'
data:
value: '* b'
value: � b
isliteral: false
- node: 2
content: '"a"'
Expand All @@ -94,7 +94,7 @@ children:
- node: 10
content: '#{x}'
data:
value: '*'
value:
isliteral: false
- node: 14
content: ' b'
Expand Down
8 changes: 5 additions & 3 deletions internal/scanner/detectors/common/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/bearer/bearer/internal/scanner/detectors/types"
)

const NonLiteralValue = "\uFFFD" // unicode Replacement character

type String struct {
Value string
IsLiteral bool
Expand Down Expand Up @@ -58,7 +60,7 @@ func ConcatenateChildStrings(node *tree.Node, detectorContext types.Context) ([]
}

if childValue == "" && !childIsLiteral {
childValue = "*"
childValue = NonLiteralValue
}

value += childValue
Expand Down Expand Up @@ -86,7 +88,7 @@ func ConcatenateAssignEquals(node *tree.Node, detectorContext types.Context) ([]
}

if left == "" && !leftIsLiteral {
left = "*"
left = NonLiteralValue

// No detection when neither parts are a string
if right == "" && !rightIsLiteral {
Expand All @@ -95,7 +97,7 @@ func ConcatenateAssignEquals(node *tree.Node, detectorContext types.Context) ([]
}

if right == "" && !rightIsLiteral {
right = "*"
right = NonLiteralValue
}

return []interface{}{String{
Expand Down
Loading