diff --git a/internal/languages/java/detectors/.snapshots/TestJavaString-string b/internal/languages/java/detectors/.snapshots/TestJavaString-string index bc4c22bf9..cedcbab2c 100644 --- a/internal/languages/java/detectors/.snapshots/TestJavaString-string +++ b/internal/languages/java/detectors/.snapshots/TestJavaString-string @@ -363,6 +363,21 @@ children: data: value: Hello World isliteral: true +- node: 44 + content: s += "!!" + data: + value: Hello World!!! + isliteral: true +- node: 57 + content: s2 += args[0] + data: + value: hey * + isliteral: false +- node: 67 + content: s2 += " there" + data: + value: hey * there + isliteral: false - node: 38 content: Greeting + "!" data: diff --git a/internal/languages/javascript/detectors/.snapshots/TestJavascriptStringDetector-string_assign_eq b/internal/languages/javascript/detectors/.snapshots/TestJavascriptStringDetector-string_assign_eq index e9818bd76..46d3f41ba 100644 --- a/internal/languages/javascript/detectors/.snapshots/TestJavascriptStringDetector-string_assign_eq +++ b/internal/languages/javascript/detectors/.snapshots/TestJavascriptStringDetector-string_assign_eq @@ -181,6 +181,21 @@ children: id: 36 range: 6:8 - 6:9 +- node: 11 + content: x += "b" + data: + value: ab + isliteral: true +- node: 19 + content: x += name + data: + value: ab* + isliteral: false +- node: 30 + content: y += "c" + data: + value: '*c' + isliteral: false - node: 6 content: '"a"' data: diff --git a/internal/languages/php/detectors/.snapshots/TestPHPString-string b/internal/languages/php/detectors/.snapshots/TestPHPString-string index d8cd6c926..720960508 100644 --- a/internal/languages/php/detectors/.snapshots/TestPHPString-string +++ b/internal/languages/php/detectors/.snapshots/TestPHPString-string @@ -1,10 +1,10 @@ type: program id: 0 -range: 1:1 - 15:3 +range: 1:1 - 18:1 dataflow_sources: - 1 - 2 - - 100 + - 117 children: - type: php_tag id: 1 @@ -12,7 +12,7 @@ children: content: "' - id: 101 - range: 15:1 - 15:3 + id: 118 + range: 17:1 - 17:3 +- node: 12 + content: '"Hello World"' + data: + value: Hello World + isliteral: true - node: 14 content: Hello World data: value: Hello World isliteral: true +- node: 52 + content: $s .= "!!" + data: + value: '*!!!' + isliteral: false +- node: 74 + content: $s2 .= $args[0] + data: + value: hey * + isliteral: false +- node: 88 + content: $s2 .= " there" + data: + value: hey * there + isliteral: false - node: 39 content: self::Greeting . "!" data: - value: '**' + value: '*!' + isliteral: false +- node: 57 + content: '"!!"' + data: + value: '!!' + isliteral: true +- node: 68 + content: '"hey "' + data: + value: 'hey ' + isliteral: true +- node: 93 + content: '" there"' + data: + value: ' there' + isliteral: true +- node: 104 + content: '"foo ''{$s2}'' bar"' + data: + value: foo 'hey * there' bar isliteral: false +- node: 46 + content: '"!"' + data: + value: '!' + isliteral: true - node: 59 content: '!!' data: @@ -472,6 +591,16 @@ children: data: value: ' there' isliteral: true +- node: 106 + content: foo ' + data: + value: foo ' + isliteral: true +- node: 112 + content: ''' bar' + data: + value: ''' bar' + isliteral: true - node: 48 content: '!' data: diff --git a/internal/languages/php/detectors/string/string.go b/internal/languages/php/detectors/string/string.go index 1b77938ab..1993b87dd 100644 --- a/internal/languages/php/detectors/string/string.go +++ b/internal/languages/php/detectors/string/string.go @@ -28,10 +28,17 @@ func (detector *stringDetector) DetectAt( ) ([]interface{}, error) { switch node.Type() { case "string": + value := node.Content() + if node.Parent() != nil && node.Parent().Type() != "encapsed_string" { + value = stringutil.StripQuotes(value) + } + return []interface{}{common.String{ - Value: stringutil.StripQuotes(node.Content()), + Value: value, IsLiteral: true, }}, nil + case "encapsed_string": + return common.ConcatenateChildStrings(node, detectorContext) case "binary_expression": if node.Children()[1].Content() == "." { return common.ConcatenateChildStrings(node, detectorContext) diff --git a/internal/languages/php/detectors/testdata/string.php b/internal/languages/php/detectors/testdata/string.php index 6ddb251ac..395d88ac2 100644 --- a/internal/languages/php/detectors/testdata/string.php +++ b/internal/languages/php/detectors/testdata/string.php @@ -10,6 +10,8 @@ public static function main($args) $s2 = "hey "; $s2 .= $args[0]; $s2 .= " there"; + + $s3 = "foo '{$s2}' bar"; } } -?> \ No newline at end of file +?> diff --git a/internal/languages/ruby/detectors/.snapshots/TestRubyStringDetector-string_assign_eq b/internal/languages/ruby/detectors/.snapshots/TestRubyStringDetector-string_assign_eq index f4346c113..da9671ae1 100644 --- a/internal/languages/ruby/detectors/.snapshots/TestRubyStringDetector-string_assign_eq +++ b/internal/languages/ruby/detectors/.snapshots/TestRubyStringDetector-string_assign_eq @@ -149,6 +149,21 @@ children: id: 29 range: 6:8 - 6:9 +- node: 8 + content: x += "b" + data: + value: ab + isliteral: true +- node: 15 + content: x += name + data: + value: ab* + isliteral: false +- node: 23 + content: y += "c" + data: + value: '*c' + isliteral: false - node: 4 content: '"a"' data: diff --git a/internal/scanner/detectors/common/string.go b/internal/scanner/detectors/common/string.go index 442256ba8..1b00c83e9 100644 --- a/internal/scanner/detectors/common/string.go +++ b/internal/scanner/detectors/common/string.go @@ -1,8 +1,6 @@ package common import ( - "fmt" - "github.com/bearer/bearer/internal/scanner/ast/traversalstrategy" "github.com/bearer/bearer/internal/scanner/ast/tree" "github.com/bearer/bearer/internal/scanner/ruleset" @@ -77,15 +75,7 @@ func ConcatenateChildStrings(node *tree.Node, detectorContext types.Context) ([] } func ConcatenateAssignEquals(node *tree.Node, detectorContext types.Context) ([]interface{}, error) { - dataflowSources := node.ChildByFieldName("left").DataflowSources() - if len(dataflowSources) == 0 { - return nil, nil - } - if len(dataflowSources) != 1 { - return nil, fmt.Errorf("expected exactly one data source for `+=` node but got %d", len(dataflowSources)) - } - - left, leftIsLiteral, err := GetStringValue(dataflowSources[0], detectorContext) + left, leftIsLiteral, err := GetStringValue(node.ChildByFieldName("left"), detectorContext) if err != nil { return nil, err }