FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
forms-angular/audit-filter.js at main · forms-angular/forms-angular · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
forms-angular
/
forms-angular
Public
Notifications
You must be signed in to change notification settings
Fork
80
Star
411
Code
Issues
5
Pull requests
6
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
forms-angular
/
audit-filter.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
179 lines (160 loc) · 6.25 KB
Breadcrumbs
forms-angular
/
audit-filter.js
Copy path
File metadata and controls
179 lines (160 loc) · 6.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
Script to take json output from npm audit and check that all vulnerabilities have got mitigations logged in package.json
*/
import
child
from
"child_process"
;
import
path
from
"path"
;
import
fs
from
"fs"
;
import
{
program
}
from
"commander"
;
import
{
fileURLToPath
}
from
"url"
;
const
__filename
=
fileURLToPath
(
import
.
meta
.
url
)
;
const
__dirname
=
path
.
dirname
(
__filename
)
;
program
.
argument
(
'[directory]'
,
'project directory to audit'
,
'.'
)
.
option
(
'-s, --severity <level>'
,
'minimum severity level to include in the report'
,
'high'
)
.
parse
(
process
.
argv
)
;
const
options
=
program
.
opts
(
)
;
const
pwd
=
path
.
resolve
(
program
.
args
[
0
]
||
'.'
)
;
const
minSeverity
=
options
.
severity
.
toLowerCase
(
)
;
const
severityHierarchy
=
{
'info'
:
0
,
'low'
:
1
,
'moderate'
:
2
,
'high'
:
3
,
'critical'
:
4
}
;
const
minSeverityValue
=
severityHierarchy
[
minSeverity
]
!==
undefined
?
severityHierarchy
[
minSeverity
]
:
3
;
const
logAndAlert
=
(
msg
)
=>
{
console
.
log
(
msg
)
;
child
.
exec
(
"paplay /usr/share/sounds/freedesktop/stereo/bell.oga"
)
;
}
;
const
mergeMitigations
=
(
target
,
source
)
=>
{
for
(
const
key
in
source
)
{
if
(
Array
.
isArray
(
source
[
key
]
)
)
{
target
[
key
]
=
(
target
[
key
]
||
[
]
)
.
concat
(
source
[
key
]
)
;
// Ensure unique entries by stringifying and parsing (basic deduplication)
const
unique
=
[
]
;
const
seen
=
new
Set
(
)
;
for
(
const
item
of
target
[
key
]
)
{
const
s
=
JSON
.
stringify
(
item
)
;
if
(
!
seen
.
has
(
s
)
)
{
seen
.
add
(
s
)
;
unique
.
push
(
item
)
;
}
}
target
[
key
]
=
unique
;
}
else
if
(
typeof
source
[
key
]
===
'object'
&&
source
[
key
]
!==
null
)
{
target
[
key
]
=
Object
.
assign
(
target
[
key
]
||
{
}
,
source
[
key
]
)
;
}
else
{
target
[
key
]
=
source
[
key
]
;
}
}
return
target
;
}
;
// read package.json
let
projectPackageJson
;
try
{
projectPackageJson
=
JSON
.
parse
(
fs
.
readFileSync
(
path
.
join
(
pwd
,
"./package.json"
)
,
'utf8'
)
)
;
}
catch
(
e
)
{
console
.
error
(
`Failed to load package.json from
${
pwd
}
`
)
;
process
.
exit
(
projectPackageJson
&&
projectPackageJson
.
name
===
'forms-angular'
?
0
:
1
)
;
}
let
modulePackageJson
;
try
{
modulePackageJson
=
JSON
.
parse
(
fs
.
readFileSync
(
path
.
join
(
__dirname
,
"./package.json"
)
,
'utf8'
)
)
;
}
catch
(
e
)
{
// If we can't load the module's package.json, we just continue with the project's one
}
const
packageJson
=
projectPackageJson
||
modulePackageJson
;
const
mitigations
=
mergeMitigations
(
JSON
.
parse
(
JSON
.
stringify
(
modulePackageJson
?.
npmAuditMitigations
||
{
}
)
)
,
projectPackageJson
?.
npmAuditMitigations
||
{
}
)
;
// Determine package manager and audit command
const
packageManager
=
(
packageJson
.
packageManager
||
"npm"
)
.
split
(
"@"
)
[
0
]
;
let
auditCommand
;
if
(
packageManager
===
"pnpm"
)
{
auditCommand
=
"pnpm audit --prod --json"
;
}
else
{
auditCommand
=
"npm audit --omit dev --json"
;
}
// Shell out and run audit command
child
.
exec
(
auditCommand
,
{
cwd
:
pwd
}
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
&&
!
stdout
)
{
console
.
error
(
`Audit command failed with error:
${
error
.
message
}
`
)
;
if
(
stderr
)
{
console
.
error
(
`stderr:
${
stderr
}
`
)
;
}
return
;
}
let
concerns
;
try
{
concerns
=
JSON
.
parse
(
stdout
)
;
}
catch
(
e
)
{
console
.
error
(
"Failed to parse audit output:"
,
e
)
;
if
(
stderr
)
{
console
.
error
(
"stderr output from audit command:"
)
;
console
.
error
(
stderr
)
;
}
if
(
stdout
)
{
console
.
error
(
"stdout output from audit command (first 200 chars):"
)
;
console
.
error
(
stdout
.
substring
(
0
,
200
)
)
;
}
else
{
console
.
error
(
"stdout was empty."
)
;
}
return
;
}
// Normalise output: npm v7+ uses vulnerabilities, pnpm uses advisories
let
vulnerabilities
=
{
}
;
if
(
concerns
.
vulnerabilities
)
{
// npm format
vulnerabilities
=
concerns
.
vulnerabilities
;
}
else
if
(
concerns
.
advisories
)
{
// pnpm format - convert advisories to a similar structure
for
(
const
id
in
concerns
.
advisories
)
{
const
advisory
=
concerns
.
advisories
[
id
]
;
const
moduleName
=
advisory
.
module_name
;
if
(
!
vulnerabilities
[
moduleName
]
)
{
vulnerabilities
[
moduleName
]
=
{
via
:
[
]
}
;
}
vulnerabilities
[
moduleName
]
.
via
.
push
(
{
url
:
advisory
.
url
,
title
:
advisory
.
title
,
severity
:
advisory
.
severity
}
)
;
}
}
for
(
const
module
in
vulnerabilities
)
{
let
vulns
=
vulnerabilities
[
module
]
.
via
;
let
moduleMitigations
=
mitigations
[
module
]
;
for
(
let
i
=
0
;
i
<
vulns
.
length
;
i
++
)
{
let
vuln
=
vulns
[
i
]
;
let
key
=
(
typeof
vuln
===
'string'
)
?
vuln
:
vuln
.
url
;
let
severity
=
(
typeof
vuln
===
'string'
)
?
'unknown'
:
(
vuln
.
severity
||
'unknown'
)
;
let
severityValue
=
severityHierarchy
[
severity
]
!==
undefined
?
severityHierarchy
[
severity
]
:
-
1
;
if
(
severityValue
<
minSeverityValue
&&
severity
!==
'unknown'
)
{
continue
;
}
// We are not interested in vulns that are due to vulns in other packages we already know about
if
(
key
&&
!
mitigations
[
key
]
)
{
if
(
!
moduleMitigations
)
{
logAndAlert
(
`Need to look at new
${
severity
}
${
module
}
vuln:
${
key
}
${
vuln
.
title
||
''
}
`
)
;
}
else
{
let
mitigation
=
moduleMitigations
.
find
(
o
=>
{
return
!
!
o
[
key
]
;
}
)
;
if
(
mitigation
)
{
mitigation
=
mitigation
[
key
]
;
if
(
mitigation
.
nextReview
)
{
const
reviewDate
=
new
Date
(
mitigation
.
nextReview
)
;
if
(
reviewDate
<
new
Date
(
)
)
{
logAndAlert
(
`Need to review
${
severity
}
${
module
}
vuln at:
${
key
}
${
mitigation
.
reviewBy
}
`
)
;
}
}
}
else
{
logAndAlert
(
`Need to look at new
${
severity
}
${
module
}
vuln:
${
key
}
${
vuln
.
title
||
''
}
`
)
;
}
}
}
}
}
}
)
;
Back
|
FazBrowse Home
|
New Git URL