shield_ast 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/shield_ast/sast.rb +21 -7
- data/lib/shield_ast/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247e09e12b6a38c007410fc314f9f4582830b4efcdea6cf8517b626293943b4d
|
4
|
+
data.tar.gz: cb5cf723c2a68c549523a9aa80000f533936e71bb419a22ebbfaf19beb04a910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 967142208a50c569075d39b36b5cc77284f5bd855efc5fc4ead3d266b67a0b4d0c73aeac57344900dba1f9bbe54543322302bf9f350588de0ccd7f8c72bdd6fb
|
7
|
+
data.tar.gz: 81e19d8e42c2baa7c01af184204def0971b608deadaa007c9b2737deb10f56e462d042e78bd2aa8869779d0210267f0051e65dc3f422092eee131cd4834c9c3e
|
data/lib/shield_ast/sast.rb
CHANGED
@@ -7,21 +7,35 @@ require "open3"
|
|
7
7
|
module ShieldAst
|
8
8
|
# Wraps the logic for running SAST scan using Semgrep.
|
9
9
|
class SAST
|
10
|
+
EXCLUDE_PATTERNS = %w[**/spec/ **/test/ **/tests/ **/features/ **/__tests__/ **/vendor/
|
11
|
+
**/node_modules/ **/*_spec.rb **/*_test.rb **/*.spec.js **/*.test.js
|
12
|
+
**/*.spec.ts **/*.test.ts **/*_test.py **/test_*.py **/*_test.go].freeze
|
13
|
+
|
10
14
|
def self.scan(path)
|
11
|
-
cmd =
|
12
|
-
"semgrep", "scan", "--config", "p/r2c-ci", "--config", "p/secrets", "--json", "--disable-version-check", path
|
13
|
-
]
|
15
|
+
cmd = build_command(path)
|
14
16
|
stdout, stderr, status = Open3.capture3(*cmd)
|
15
17
|
|
16
18
|
if status.success?
|
17
19
|
JSON.parse(stdout)
|
18
20
|
else
|
19
|
-
warn "Semgrep SAST scan failed!
|
20
|
-
[]
|
21
|
+
warn "Semgrep SAST scan failed! Exit Code: #{status.exitstatus}\nError: #{stderr}"
|
22
|
+
{ "results" => [] }
|
21
23
|
end
|
22
24
|
rescue JSON::ParserError => e
|
23
|
-
warn "Failed to parse Semgrep output: #{e.message}"
|
24
|
-
[]
|
25
|
+
warn "Failed to parse Semgrep SAST output: #{e.message}"
|
26
|
+
{ "results" => [] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.build_command(path)
|
30
|
+
base_cmd = %w[semgrep scan --config p/r2c-ci --config p/secrets --json --disable-version-check]
|
31
|
+
|
32
|
+
EXCLUDE_PATTERNS.each do |pattern|
|
33
|
+
base_cmd.push("--exclude", pattern)
|
34
|
+
end
|
35
|
+
|
36
|
+
base_cmd.push(path)
|
37
|
+
|
38
|
+
base_cmd
|
25
39
|
end
|
26
40
|
end
|
27
41
|
end
|
data/lib/shield_ast/version.rb
CHANGED