1
1
#! /bin/bash
2
2
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
4
4
# then reports via sarif format
5
5
# usage: dependencies <path to repo>
6
6
7
7
8
- # rule: checked in dependencies
9
- # rule: vendor dependencies in repo
10
8
set -euo pipefail
11
9
which git > /dev/null || exit 1
12
10
which dotnet > /dev/null || exit 1
@@ -47,7 +45,7 @@ report() {
47
45
48
46
check_dll () {
49
47
local file=$1
50
- # ensure that the file isn't System. or Web.
48
+ # ensure that the csproj_file isn't System. or Web.
51
49
# but report a more specific thing if it's a framework dependency
52
50
dll_assembly_info " $source /$file " | grep -qE ' ^System.|^Web.|^Microsoft'
53
51
}
@@ -59,22 +57,53 @@ check_jar() {
59
57
jar_manifest_info " $source /$file " | grep -iqE ' apache|google|sun|oracle'
60
58
}
61
59
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
+ }
63
65
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
71
68
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
73
88
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
76
100
done
101
+ }
102
+
103
+ look_for_busted_hint_paths
104
+ find_package_config_files
105
+ look_for_dependencies_in_source
77
106
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} "
79
108
80
109
rm -rf " ${tmp} "
0 commit comments