Skip to content

Commit fe8d755

Browse files
committed
Fix bearer, add dependency findings
* Bearer script was too complicated and missed the nonzero exit code * Dependencies tool will look for deprecated package management approaches
1 parent dbb4b4b commit fe8d755

File tree

6 files changed

+53
-23
lines changed

6 files changed

+53
-23
lines changed

Gemfile.lock

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ GEM
1010
rainbow (3.1.1)
1111
regexp_parser (2.7.0)
1212
rexml (3.3.6)
13-
strscan
1413
rspec (3.13.0)
1514
rspec-core (~> 3.13.0)
1615
rspec-expectations (~> 3.13.0)
@@ -37,11 +36,11 @@ GEM
3736
rubocop-ast (1.28.0)
3837
parser (>= 3.2.1.0)
3938
ruby-progressbar (1.13.0)
40-
strscan (3.1.0)
4139
unicode-display_width (2.4.2)
4240

4341
PLATFORMS
4442
arm64-darwin-21
43+
arm64-darwin-22
4544
x86_64-linux
4645

4746
DEPENDENCIES

html_report.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def generate
100100
self
101101
end
102102

103+
104+
# add in tool
105+
#
103106
def results_matching(severity, rule_id)
104107
@results.select do |result|
105108
_description = result.description
@@ -115,7 +118,7 @@ def rules_and_descriptions(severity)
115118

116119
def publish
117120
# generate erb template and write to the file from destination_path
118-
File.open(@dest_path, 'w') do |file|
121+
File.open(@dest_path, 'w+') do |file|
119122
html = ERB.new(self.class.template).result(binding)
120123
file.write(html)
121124
end

spec/bearer.sarif

+1
Large diffs are not rendered by default.

spec/html_report_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
it 'handles a directory of one or more sarif files' do
2424
report = HtmlReport.new("spec", nil)
2525
report.generate
26-
expect(report.results.first.description.split("\n")[0]).to match "Suspicious use of netcat with IP address"
26+
expect(report.results.first.description.split("\n")[0]).to match "Usage of hard-coded secret"
2727
end
2828

2929
it 'publishes a simple html report' do

tools.d/bearer

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@ set -euo pipefail
44
which bearer > /dev/null || exit 1
55
source=$1
66

7-
tmpdir=$(mktemp -d)
8-
bearer scan --quiet -f sarif "${source}" --output "${tmpdir}/bearer.sarif" 1>&2
9-
cat "${tmpdir}/bearer.sarif"
7+
bearer scan --quiet --exit-code 0 -f sarif "${source}"

tools.d/dependencies

+45-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/bin/bash
22

3-
# finds jar files or dlls that are checked into git repo, and checks if they are available in nuget
3+
# finds jar csproj_files or dlls that are checked into git repo, and checks if they are available in nuget
44
# then reports via sarif format
55
# usage: dependencies <path to repo>
66

77

8-
# rule: checked in dependencies
9-
# rule: vendor dependencies in repo
108
set -euo pipefail
119
which git > /dev/null || exit 1
1210
which dotnet > /dev/null || exit 1
@@ -47,7 +45,7 @@ report() {
4745

4846
check_dll() {
4947
local file=$1
50-
# ensure that the file isn't System. or Web.
48+
# ensure that the csproj_file isn't System. or Web.
5149
# but report a more specific thing if it's a framework dependency
5250
dll_assembly_info "$source/$file" | grep -qE '^System.|^Web.|^Microsoft'
5351
}
@@ -59,22 +57,53 @@ check_jar() {
5957
jar_manifest_info "$source/$file" | grep -iqE 'apache|google|sun|oracle'
6058
}
6159

62-
(cd "$source" && git ls-files | grep -E '\.jar$|\.dll$') | while read -r file; do
60+
find_package_config_files() {
61+
find "$source" -iname "packages.config" | while read -r file; do
62+
report "old-nuget-configuration" "Nuget dependencies should be declared in a PackageResource" "${file}"
63+
done
64+
}
6365

64-
if [[ $file =~ \.dll ]] && check_dll "${file}"; then
65-
report "checked-in-framework-dependencies" "Framework dependencies checked in to source control" "${file}"
66-
elif [[ $file =~ \.jar ]] && check_jar "${file}"; then
67-
report "checked-in-thirdparty-dependencies" "Third party dependencies checked in to source control" "${file}"
68-
else
69-
report "checked-in-dependencies" "dependencies checked in to source control" "${file}"
70-
fi
66+
process_hint_paths() {
67+
local csproj_file=$1
7168

72-
done
69+
grep -E '<HintPath>.*</HintPath>' "$csproj_file" | while read -r hint_path_entry; do
70+
proj_dir=$(dirname "$csproj_file")
71+
hintpath=$(echo "$hint_path_entry" | sed -E 's/.*<HintPath>(.*)<\/HintPath>.*/\1/' | sed -E 's/\\/\//g')
72+
if [[ ! -f "${proj_dir}/$hintpath" ]]; then
73+
report "hintpath-missing-file" "Missing DLL in Hint Path" "${csproj_file}"
74+
fi
75+
done
76+
}
77+
78+
look_for_dependencies_in_source() {
79+
(cd "$source" && git ls-files | grep -E '\.jar$|\.dll$') | while read -r file; do
80+
81+
if [[ $file =~ \.dll ]] && check_dll "${file}"; then
82+
report "checked-in-framework-dependencies" "Framework dependencies checked in to source control" "${file}"
83+
elif [[ $file =~ \.jar ]] && check_jar "${file}"; then
84+
report "checked-in-thirdparty-dependencies" "Third party dependencies checked in to source control" "${file}"
85+
else
86+
report "checked-in-dependencies" "dependencies checked in to source control" "${file}"
87+
fi
7388

74-
find "$source" -iname "packages.config" | while read -r file; do
75-
report "old-nuget-configuration" "Nuget dependencies should be declared in a PackageResource" "${file}"
89+
done
90+
}
91+
92+
look_for_busted_hint_paths() {
93+
# is there a csproj csproj_file with a Resource declared that has a HintPath attribute? And does the Hintpath exist?
94+
# then does the Resource version match the version from the artifact in the HintPath?
95+
96+
find "$source" -iname "*.csproj" | while read -r csproj_file; do
97+
if grep -qi HintPath "$csproj_file"; then
98+
process_hint_paths "$csproj_file"
99+
fi
76100
done
101+
}
102+
103+
look_for_busted_hint_paths
104+
find_package_config_files
105+
look_for_dependencies_in_source
77106

78-
PATH="${brew_prefix}/opt/statica/libexec:.:$PATH" csv2sarif "depenencies" "0.1" "${findings_csv}"
107+
PATH="${brew_prefix}/opt/statica/libexec:.:$PATH" csv2sarif "dependencies" "0.1" "${findings_csv}"
79108

80109
rm -rf "${tmp}"

0 commit comments

Comments
 (0)