@vltpkg/query 0.0.0-5 → 0.0.0-7
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.
- package/README.md +107 -1
- package/dist/esm/index.d.ts +12 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +54 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pseudo/abandoned.d.ts +5 -0
- package/dist/esm/pseudo/abandoned.d.ts.map +1 -0
- package/dist/esm/pseudo/abandoned.js +6 -0
- package/dist/esm/pseudo/abandoned.js.map +1 -0
- package/dist/esm/pseudo/confused.d.ts +5 -0
- package/dist/esm/pseudo/confused.d.ts.map +1 -0
- package/dist/esm/pseudo/confused.js +6 -0
- package/dist/esm/pseudo/confused.js.map +1 -0
- package/dist/esm/pseudo/cve.d.ts +10 -0
- package/dist/esm/pseudo/cve.d.ts.map +1 -0
- package/dist/esm/pseudo/cve.js +47 -0
- package/dist/esm/pseudo/cve.js.map +1 -0
- package/dist/esm/pseudo/cwe.d.ts +10 -0
- package/dist/esm/pseudo/cwe.d.ts.map +1 -0
- package/dist/esm/pseudo/cwe.js +46 -0
- package/dist/esm/pseudo/cwe.js.map +1 -0
- package/dist/esm/pseudo/debug.d.ts +5 -0
- package/dist/esm/pseudo/debug.d.ts.map +1 -0
- package/dist/esm/pseudo/debug.js +6 -0
- package/dist/esm/pseudo/debug.js.map +1 -0
- package/dist/esm/pseudo/deprecated.d.ts +5 -0
- package/dist/esm/pseudo/deprecated.d.ts.map +1 -0
- package/dist/esm/pseudo/deprecated.js +6 -0
- package/dist/esm/pseudo/deprecated.js.map +1 -0
- package/dist/esm/pseudo/dynamic.d.ts +5 -0
- package/dist/esm/pseudo/dynamic.d.ts.map +1 -0
- package/dist/esm/pseudo/dynamic.js +6 -0
- package/dist/esm/pseudo/dynamic.js.map +1 -0
- package/dist/esm/pseudo/entropic.d.ts +5 -0
- package/dist/esm/pseudo/entropic.d.ts.map +1 -0
- package/dist/esm/pseudo/entropic.js +6 -0
- package/dist/esm/pseudo/entropic.js.map +1 -0
- package/dist/esm/pseudo/env.d.ts +5 -0
- package/dist/esm/pseudo/env.d.ts.map +1 -0
- package/dist/esm/pseudo/env.js +6 -0
- package/dist/esm/pseudo/env.js.map +1 -0
- package/dist/esm/pseudo/eval.d.ts +5 -0
- package/dist/esm/pseudo/eval.d.ts.map +1 -0
- package/dist/esm/pseudo/eval.js +6 -0
- package/dist/esm/pseudo/eval.js.map +1 -0
- package/dist/esm/pseudo/fs.d.ts +5 -0
- package/dist/esm/pseudo/fs.d.ts.map +1 -0
- package/dist/esm/pseudo/fs.js +6 -0
- package/dist/esm/pseudo/fs.js.map +1 -0
- package/dist/esm/pseudo/helpers.d.ts +4 -0
- package/dist/esm/pseudo/helpers.d.ts.map +1 -1
- package/dist/esm/pseudo/helpers.js +19 -0
- package/dist/esm/pseudo/helpers.js.map +1 -1
- package/dist/esm/pseudo/license.d.ts +10 -0
- package/dist/esm/pseudo/license.d.ts.map +1 -0
- package/dist/esm/pseudo/license.js +61 -0
- package/dist/esm/pseudo/license.js.map +1 -0
- package/dist/esm/pseudo/malware.d.ts +10 -0
- package/dist/esm/pseudo/malware.d.ts.map +1 -0
- package/dist/esm/pseudo/malware.js +60 -0
- package/dist/esm/pseudo/malware.js.map +1 -0
- package/dist/esm/pseudo/minified.d.ts +5 -0
- package/dist/esm/pseudo/minified.d.ts.map +1 -0
- package/dist/esm/pseudo/minified.js +6 -0
- package/dist/esm/pseudo/minified.js.map +1 -0
- package/dist/esm/pseudo/native.d.ts +5 -0
- package/dist/esm/pseudo/native.d.ts.map +1 -0
- package/dist/esm/pseudo/native.js +6 -0
- package/dist/esm/pseudo/native.js.map +1 -0
- package/dist/esm/pseudo/network.d.ts +5 -0
- package/dist/esm/pseudo/network.d.ts.map +1 -0
- package/dist/esm/pseudo/network.js +6 -0
- package/dist/esm/pseudo/network.js.map +1 -0
- package/dist/esm/pseudo/obfuscated.d.ts +5 -0
- package/dist/esm/pseudo/obfuscated.d.ts.map +1 -0
- package/dist/esm/pseudo/obfuscated.js +6 -0
- package/dist/esm/pseudo/obfuscated.js.map +1 -0
- package/dist/esm/pseudo/scripts.d.ts +5 -0
- package/dist/esm/pseudo/scripts.d.ts.map +1 -0
- package/dist/esm/pseudo/scripts.js +6 -0
- package/dist/esm/pseudo/scripts.js.map +1 -0
- package/dist/esm/pseudo/severity.d.ts +10 -0
- package/dist/esm/pseudo/severity.d.ts.map +1 -0
- package/dist/esm/pseudo/severity.js +60 -0
- package/dist/esm/pseudo/severity.js.map +1 -0
- package/dist/esm/pseudo/shell.d.ts +5 -0
- package/dist/esm/pseudo/shell.d.ts.map +1 -0
- package/dist/esm/pseudo/shell.js +6 -0
- package/dist/esm/pseudo/shell.js.map +1 -0
- package/dist/esm/pseudo/shrinkwrap.d.ts +5 -0
- package/dist/esm/pseudo/shrinkwrap.d.ts.map +1 -0
- package/dist/esm/pseudo/shrinkwrap.js +6 -0
- package/dist/esm/pseudo/shrinkwrap.js.map +1 -0
- package/dist/esm/pseudo/squat.d.ts +10 -0
- package/dist/esm/pseudo/squat.d.ts.map +1 -0
- package/dist/esm/pseudo/squat.js +57 -0
- package/dist/esm/pseudo/squat.js.map +1 -0
- package/dist/esm/pseudo/suspicious.d.ts +5 -0
- package/dist/esm/pseudo/suspicious.d.ts.map +1 -0
- package/dist/esm/pseudo/suspicious.js +6 -0
- package/dist/esm/pseudo/suspicious.js.map +1 -0
- package/dist/esm/pseudo/tracker.d.ts +5 -0
- package/dist/esm/pseudo/tracker.d.ts.map +1 -0
- package/dist/esm/pseudo/tracker.js +6 -0
- package/dist/esm/pseudo/tracker.js.map +1 -0
- package/dist/esm/pseudo/trivial.d.ts +5 -0
- package/dist/esm/pseudo/trivial.d.ts.map +1 -0
- package/dist/esm/pseudo/trivial.js +6 -0
- package/dist/esm/pseudo/trivial.js.map +1 -0
- package/dist/esm/pseudo/undesirable.d.ts +5 -0
- package/dist/esm/pseudo/undesirable.d.ts.map +1 -0
- package/dist/esm/pseudo/undesirable.js +6 -0
- package/dist/esm/pseudo/undesirable.js.map +1 -0
- package/dist/esm/pseudo/unknown.d.ts +5 -0
- package/dist/esm/pseudo/unknown.d.ts.map +1 -0
- package/dist/esm/pseudo/unknown.js +6 -0
- package/dist/esm/pseudo/unknown.js.map +1 -0
- package/dist/esm/pseudo/unmaintained.d.ts +5 -0
- package/dist/esm/pseudo/unmaintained.d.ts.map +1 -0
- package/dist/esm/pseudo/unmaintained.js +6 -0
- package/dist/esm/pseudo/unmaintained.js.map +1 -0
- package/dist/esm/pseudo/unpopular.d.ts +5 -0
- package/dist/esm/pseudo/unpopular.d.ts.map +1 -0
- package/dist/esm/pseudo/unpopular.js +6 -0
- package/dist/esm/pseudo/unpopular.js.map +1 -0
- package/dist/esm/pseudo/unstable.d.ts +5 -0
- package/dist/esm/pseudo/unstable.d.ts.map +1 -0
- package/dist/esm/pseudo/unstable.js +6 -0
- package/dist/esm/pseudo/unstable.js.map +1 -0
- package/dist/esm/pseudo.d.ts.map +1 -1
- package/dist/esm/pseudo.js +69 -4
- package/dist/esm/pseudo.js.map +1 -1
- package/dist/esm/types.d.ts +2 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The **vlt** query syntax engine.
|
|
|
12
12
|
```js
|
|
13
13
|
import { Query } from '@vltpkg/query'
|
|
14
14
|
|
|
15
|
-
const query = new Query({ nodes })
|
|
15
|
+
const query = new Query({ nodes, specOptions, securityArchive })
|
|
16
16
|
query.search(':root > *')
|
|
17
17
|
```
|
|
18
18
|
|
|
@@ -160,3 +160,109 @@ e.g: `#foo` is the same as `[name=foo]`
|
|
|
160
160
|
- `:root` Returns the root node, that represents the package defined
|
|
161
161
|
at the top-level `package.json` of your project folder.
|
|
162
162
|
- `:scope` Returns the current scope of a given selector
|
|
163
|
+
|
|
164
|
+
### Security Selectors
|
|
165
|
+
|
|
166
|
+
The following pseudo-selectors rely on security data provided by
|
|
167
|
+
[Socket](https://socket.dev/), the usage of any of these selectors is
|
|
168
|
+
going to require a network call to hydrate package report data. Keep
|
|
169
|
+
in mind that this is going to slow down end-user query usage since the
|
|
170
|
+
security data needs to be fetched prior to a `Query` instantiation.
|
|
171
|
+
|
|
172
|
+
- `:abandoned` Matches packages that were published by an npm account
|
|
173
|
+
that no longer exists.
|
|
174
|
+
- `:confused` Matches packages affected by manifest confusion. This
|
|
175
|
+
could be malicious or caused by an error when publishing the
|
|
176
|
+
package.
|
|
177
|
+
- `:cve(<id>)` Matches packages that have a CVE alert with the
|
|
178
|
+
specified CVE ID. The ID parameter is required and should be a valid
|
|
179
|
+
CVE identifier (e.g., `CVE-2023-1234`). This selector can be used to
|
|
180
|
+
find packages affected by specific known vulnerabilities.
|
|
181
|
+
- `:cwe(<id>)` Matches packages that have a CWE alert with the
|
|
182
|
+
specified CWE ID. The ID parameter is required and should be a valid
|
|
183
|
+
CWE identifier (e.g., `CWE-79`).
|
|
184
|
+
- `:debug` Matches packages that use debug, reflection and dynamic
|
|
185
|
+
code execution features.
|
|
186
|
+
- `:deprecated` Matches packages marked as deprecated. This could
|
|
187
|
+
indicate that a single version should not be used, or that the
|
|
188
|
+
package is no longer maintained and any new vulnerabilities will not
|
|
189
|
+
be fixed.
|
|
190
|
+
- `:dynamic` Matches packages that uses dynamic imports.
|
|
191
|
+
- `:entropic` Matches packages that contains high entropic strings.
|
|
192
|
+
This could be a sign of encrypted data, leaked secrets or obfuscated
|
|
193
|
+
code.
|
|
194
|
+
- `:env` Matches packages that accesses environment variables, which
|
|
195
|
+
may be a sign of credential stuffing or data theft.
|
|
196
|
+
- `:eval` Matches packages that use dynamic code execution (e.g.,
|
|
197
|
+
eval()), which is a dangerous practice. This can prevent the code
|
|
198
|
+
from running in certain environments and increases the risk that the
|
|
199
|
+
code may contain exploits or malicious behavior.
|
|
200
|
+
- `:fs` Matches packages that accesses the file system, and could
|
|
201
|
+
potentially read sensitive data.
|
|
202
|
+
- `:license(<type>)` Matches packages based on different potential
|
|
203
|
+
license issues:
|
|
204
|
+
- `:license(unlicensed)` Matches packages with no license.
|
|
205
|
+
- `:license(misc)` Matches packages with fine-grained problems.
|
|
206
|
+
- `:license(restricted)` Matches packages with a license that is not
|
|
207
|
+
permissive.
|
|
208
|
+
- `:license(ambiguous)` Matches packages with ambiguous licensing.
|
|
209
|
+
- `:license(copyleft)` Matches packages with a copyleft license.
|
|
210
|
+
- `:license(unknown)` Matches packages that have potential license
|
|
211
|
+
data but its type could not be determined.
|
|
212
|
+
- `:license(none)` Matches packages that have no license data.
|
|
213
|
+
- `:license(exception)` Matches packages that have SPDX license
|
|
214
|
+
exception.
|
|
215
|
+
- `:malware(<type>)` Matches packages that may contain malware. The
|
|
216
|
+
type parameter is required and can be one of the following:
|
|
217
|
+
- `critical` or `0`
|
|
218
|
+
- `high` or `1`
|
|
219
|
+
- `medium` or `2`
|
|
220
|
+
- `low` or `3`
|
|
221
|
+
- `:minified` Matches packages that contain minified code. This may be
|
|
222
|
+
harmless in some cases where minified code is included in packaged
|
|
223
|
+
libraries.
|
|
224
|
+
- `:native` Matches packages that contain native code (e.g., compiled
|
|
225
|
+
binaries or shared libraries). Including native code can obscure
|
|
226
|
+
malicious behavior.
|
|
227
|
+
- `:network` Matches packages that access the network.
|
|
228
|
+
- `:obfuscated` Matches packages that use obfuscated files,
|
|
229
|
+
intentionally packed to hide their behavior. This could be a sign of
|
|
230
|
+
malware.
|
|
231
|
+
- `:scripts` Matches packages that have scripts that are run when the
|
|
232
|
+
package is installed. The majority of malware in npm is hidden in
|
|
233
|
+
install scripts.
|
|
234
|
+
- `:severity` Matches packages based of the severity level of any
|
|
235
|
+
attached CVE. The type paremeter is required and can be one of the
|
|
236
|
+
following:
|
|
237
|
+
- `critical` or `0`
|
|
238
|
+
- `high` or `1`
|
|
239
|
+
- `medium` or `2`
|
|
240
|
+
- `low` or `3`
|
|
241
|
+
- `:shell` Matches packages that accesses the system shell. Accessing
|
|
242
|
+
the system shell increases the risk of executing arbitrary code.
|
|
243
|
+
- `:shrinkwrap` Matches packages that contains a shrinkwrap file. This
|
|
244
|
+
may allow the package to bypass normal install procedures.
|
|
245
|
+
- `:squat(<type>)` Matches packages with names similar to other
|
|
246
|
+
popular packages and may not be the package you want. The type
|
|
247
|
+
parameter is required and can be one of the following:
|
|
248
|
+
- `critical` or `0`
|
|
249
|
+
- `medium` or `2`
|
|
250
|
+
- `:suspicious` Matches packages that may have its GitHub repository
|
|
251
|
+
artificially inflated with stars (from bots, crowdsourcing, etc.).
|
|
252
|
+
- `:tracker` Matches packages that contains telemetry which tracks how
|
|
253
|
+
it is used.
|
|
254
|
+
- `:trivial` Matches packages that have less than 10 lines of code.
|
|
255
|
+
These packages are easily copied into your own project and may not
|
|
256
|
+
warrant the additional supply chain risk of an external dependency.
|
|
257
|
+
- `:undesirable` Matches packages that are a joke, parody, or includes
|
|
258
|
+
undocumented or hidden behavior unrelated to its primary function.
|
|
259
|
+
- `:unknown` Matches packages that have a new npm collaborator
|
|
260
|
+
publishing a version of the package for the first time. New
|
|
261
|
+
collaborators are usually benign additions to a project, but do
|
|
262
|
+
indicate a change to the security surface area of a package.
|
|
263
|
+
- `:unmaintained` Matches packages that have not been updated in more
|
|
264
|
+
than 5 years and may be unmaintained.
|
|
265
|
+
- `:unpopular` Matches packages that are not very popular.
|
|
266
|
+
- `:unstable` Matches packages with unstable ownership. This indicates
|
|
267
|
+
a new collaborator has begun publishing package versions. Package
|
|
268
|
+
stability and security risk may be elevated.
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import type { GraphLike } from '@vltpkg/graph';
|
|
2
2
|
import type { SpecOptions } from '@vltpkg/spec/browser';
|
|
3
|
+
import type { SecurityArchiveLike } from '@vltpkg/security-archive';
|
|
3
4
|
import type { ParserState, QueryResponse } from './types.ts';
|
|
4
5
|
export * from './types.ts';
|
|
5
6
|
export declare const walk: (state: ParserState) => Promise<ParserState>;
|
|
6
7
|
export type QueryOptions = {
|
|
7
8
|
graph: GraphLike;
|
|
8
9
|
specOptions: SpecOptions;
|
|
10
|
+
securityArchive: SecurityArchiveLike | undefined;
|
|
9
11
|
};
|
|
10
12
|
export declare class Query {
|
|
11
13
|
#private;
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Helper method to determine if a given query string is using any of
|
|
16
|
+
* the known security selectors. This is useful so that operations can
|
|
17
|
+
* skip hydrating the security archive if it's not needed.
|
|
18
|
+
*/
|
|
19
|
+
static hasSecuritySelectors(query: string): boolean;
|
|
20
|
+
constructor({ graph, specOptions, securityArchive }: QueryOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Search the graph for nodes and edges that match the given query.
|
|
23
|
+
*/
|
|
13
24
|
search(query: string, signal?: AbortSignal): Promise<QueryResponse>;
|
|
14
25
|
}
|
|
15
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,SAAS,EAAY,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAY,SAAS,EAAY,MAAM,eAAe,CAAA;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAYnE,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EACd,MAAM,YAAY,CAAA;AAEnB,cAAc,YAAY,CAAA;AAiC1B,eAAO,MAAM,IAAI,UACR,WAAW,KACjB,OAAO,CAAC,WAAW,CAmDrB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,SAAS,CAAA;IAChB,WAAW,EAAE,WAAW,CAAA;IACxB,eAAe,EAAE,mBAAmB,GAAG,SAAS,CAAA;CACjD,CAAA;AAqCD,qBAAa,KAAK;;IAMhB;;;;OAIG;IACH,MAAM,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;gBASvC,EAAE,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,YAAY;IAOjE;;OAEG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC;CAmD1B"}
|
package/dist/esm/index.js
CHANGED
|
@@ -74,15 +74,67 @@ export const walk = async (state) => {
|
|
|
74
74
|
}
|
|
75
75
|
return state;
|
|
76
76
|
};
|
|
77
|
+
// A list of known security selectors that rely on
|
|
78
|
+
// data from the security-archive in order to work
|
|
79
|
+
const securitySelectors = new Set([
|
|
80
|
+
':abandoned',
|
|
81
|
+
':confused',
|
|
82
|
+
':cve',
|
|
83
|
+
':debug',
|
|
84
|
+
':deprecated',
|
|
85
|
+
':dynamic',
|
|
86
|
+
':entropic',
|
|
87
|
+
':env',
|
|
88
|
+
':eval',
|
|
89
|
+
':fs',
|
|
90
|
+
':license',
|
|
91
|
+
':malware',
|
|
92
|
+
':minified',
|
|
93
|
+
':native',
|
|
94
|
+
':network',
|
|
95
|
+
':obfuscated',
|
|
96
|
+
':scripts',
|
|
97
|
+
':sev',
|
|
98
|
+
':severity',
|
|
99
|
+
':shell',
|
|
100
|
+
':shrinkwrap',
|
|
101
|
+
':squat',
|
|
102
|
+
':suspicious',
|
|
103
|
+
':tracker',
|
|
104
|
+
':trivial',
|
|
105
|
+
':undesirable',
|
|
106
|
+
':unknown',
|
|
107
|
+
':unmaintained',
|
|
108
|
+
':unpopular',
|
|
109
|
+
':unstable',
|
|
110
|
+
]);
|
|
77
111
|
export class Query {
|
|
78
112
|
#cache;
|
|
79
113
|
#graph;
|
|
80
114
|
#specOptions;
|
|
81
|
-
|
|
115
|
+
#securityArchive;
|
|
116
|
+
/**
|
|
117
|
+
* Helper method to determine if a given query string is using any of
|
|
118
|
+
* the known security selectors. This is useful so that operations can
|
|
119
|
+
* skip hydrating the security archive if it's not needed.
|
|
120
|
+
*/
|
|
121
|
+
static hasSecuritySelectors(query) {
|
|
122
|
+
for (const selector of securitySelectors) {
|
|
123
|
+
if (query.includes(selector)) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
constructor({ graph, specOptions, securityArchive }) {
|
|
82
130
|
this.#cache = new Map();
|
|
83
131
|
this.#graph = graph;
|
|
84
132
|
this.#specOptions = specOptions;
|
|
133
|
+
this.#securityArchive = securityArchive;
|
|
85
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Search the graph for nodes and edges that match the given query.
|
|
137
|
+
*/
|
|
86
138
|
async search(query, signal) {
|
|
87
139
|
if (typeof query !== 'string') {
|
|
88
140
|
throw new TypeError('Query search argument needs to be a string');
|
|
@@ -115,6 +167,7 @@ export class Query {
|
|
|
115
167
|
},
|
|
116
168
|
partial: { nodes, edges },
|
|
117
169
|
signal,
|
|
170
|
+
securityArchive: this.#securityArchive,
|
|
118
171
|
specOptions: this.#specOptions,
|
|
119
172
|
walk,
|
|
120
173
|
});
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAG3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,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GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport postcssSelectorParser from 'postcss-selector-parser'\nimport { attribute } from './attribute.ts'\nimport { classFn } from './class.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n} from './types.ts'\nimport type {\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n class: classFn,\n combinator,\n comment: noopFn,\n id,\n nesting: noopFn,\n pseudo,\n root: noopFn,\n selector: async (state: ParserState) => {\n state.partial.nodes = new Set(state.initial.nodes)\n state.partial.edges = new Set(state.initial.edges)\n return state\n },\n string: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n tag: async (state: ParserState) => {\n if (state.current.value !== '{' && state.current.value !== '}') {\n throw error('Unsupported selector', { found: state.current })\n }\n return state\n },\n universal: noopFn,\n}\nconst selectorsMap = new Map<string, ParserFn>(\n Object.entries(selectors),\n)\n\nexport const walk = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const parserFn = selectorsMap.get(state.current.type)\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Missing parser for query node: ${state.current.type}`,\n )\n }\n state = await parserFn(state)\n\n // pseudo selectors handle their own sub selectors\n if (\n isPostcssNodeWithChildren(state.current) &&\n state.current.type !== 'pseudo'\n ) {\n const node: PostcssNodeWithChildren = asPostcssNodeWithChildren(\n state.current,\n )\n\n if (node.nodes.length) {\n for (let i = 0; i < node.nodes.length; i++) {\n const current = node.nodes[i]\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!current) continue\n\n const childState: ParserState = {\n ...state,\n current,\n next: node.nodes[i + 1],\n prev: node.nodes[i - 1],\n }\n state = await walk(childState)\n }\n }\n\n if (isSelectorNode(node)) {\n for (const edge of state.partial.edges) {\n state.collect.edges.add(edge)\n }\n for (const node of state.partial.nodes) {\n state.collect.nodes.add(node)\n }\n }\n }\n return state\n}\n\nexport type QueryOptions = {\n graph: GraphLike\n specOptions: SpecOptions\n}\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n\n constructor({ graph, specOptions }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n }\n\n async search(\n query: string,\n signal?: AbortSignal,\n ): Promise<QueryResponse> {\n if (typeof query !== 'string') {\n throw new TypeError(\n 'Query search argument needs to be a string',\n )\n }\n\n if (!query) return { edges: [], nodes: [] }\n\n const cachedResult = this.#cache.get(query)\n if (cachedResult) {\n return cachedResult\n }\n\n const nodes = new Set<NodeLike>(\n Array.from(this.#graph.nodes.values()),\n )\n const edges = new Set<EdgeLike>(Array.from(this.#graph.edges))\n\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal?.throwIfAborted()\n },\n current: postcssSelectorParser().astSync(query),\n initial: {\n nodes: new Set(nodes),\n edges: new Set(edges),\n },\n collect: {\n nodes: new Set<NodeLike>(),\n edges: new Set<EdgeLike>(),\n },\n partial: { nodes, edges },\n signal,\n specOptions: this.#specOptions,\n walk,\n })\n\n const res: QueryResponse = {\n edges: Array.from(collect.edges),\n nodes: Array.from(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAI3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,OAAO,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E,CAAC,CAAC,CAAA;gBACxB,CAAC,CAAC,CAAA;gBACF,MAAM,EAAE,cAAc,EAAE,CAAA;YAC1B,CAAC;YACD,OAAO,EAAE,qBAAqB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;YAC/C,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC;gBACrB,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC;aACtB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,IAAI,GAAG,EAAY;gBAC1B,KAAK,EAAE,IAAI,GAAG,EAAY;aAC3B;YACD,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;YACzB,MAAM;YACN,eAAe,EAAE,IAAI,CAAC,gBAAgB;YACtC,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,IAAI;SACL,CAAC,CAAA;QAEF,MAAM,GAAG,GAAkB;YACzB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SACjC,CAAA;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACZ,CAAC;CACF","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { EdgeLike, GraphLike, NodeLike } from '@vltpkg/graph'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { SecurityArchiveLike } from '@vltpkg/security-archive'\nimport postcssSelectorParser from 'postcss-selector-parser'\nimport { attribute } from './attribute.ts'\nimport { classFn } from './class.ts'\nimport { combinator } from './combinator.ts'\nimport { id } from './id.ts'\nimport { pseudo } from './pseudo.ts'\nimport {\n isPostcssNodeWithChildren,\n asPostcssNodeWithChildren,\n isSelectorNode,\n} from './types.ts'\nimport type {\n PostcssNodeWithChildren,\n ParserState,\n ParserFn,\n QueryResponse,\n} from './types.ts'\n\nexport * from './types.ts'\n\nconst noopFn = async (state: ParserState) => state\n\nconst selectors = {\n attribute,\n class: classFn,\n combinator,\n comment: noopFn,\n id,\n nesting: noopFn,\n pseudo,\n root: noopFn,\n selector: async (state: ParserState) => {\n state.partial.nodes = new Set(state.initial.nodes)\n state.partial.edges = new Set(state.initial.edges)\n return state\n },\n string: async (state: ParserState) => {\n throw error('Unsupported selector', { found: state.current })\n },\n tag: async (state: ParserState) => {\n if (state.current.value !== '{' && state.current.value !== '}') {\n throw error('Unsupported selector', { found: state.current })\n }\n return state\n },\n universal: noopFn,\n}\nconst selectorsMap = new Map<string, ParserFn>(\n Object.entries(selectors),\n)\n\nexport const walk = async (\n state: ParserState,\n): Promise<ParserState> => {\n await state.cancellable()\n\n const parserFn = selectorsMap.get(state.current.type)\n\n if (!parserFn) {\n if (state.loose) {\n return state\n }\n\n throw new Error(\n `Missing parser for query node: ${state.current.type}`,\n )\n }\n state = await parserFn(state)\n\n // pseudo selectors handle their own sub selectors\n if (\n isPostcssNodeWithChildren(state.current) &&\n state.current.type !== 'pseudo'\n ) {\n const node: PostcssNodeWithChildren = asPostcssNodeWithChildren(\n state.current,\n )\n\n if (node.nodes.length) {\n for (let i = 0; i < node.nodes.length; i++) {\n const current = node.nodes[i]\n /* c8 ignore next -- impossible but TS doesn't know that */\n if (!current) continue\n\n const childState: ParserState = {\n ...state,\n current,\n next: node.nodes[i + 1],\n prev: node.nodes[i - 1],\n }\n state = await walk(childState)\n }\n }\n\n if (isSelectorNode(node)) {\n for (const edge of state.partial.edges) {\n state.collect.edges.add(edge)\n }\n for (const node of state.partial.nodes) {\n state.collect.nodes.add(node)\n }\n }\n }\n return state\n}\n\nexport type QueryOptions = {\n graph: GraphLike\n specOptions: SpecOptions\n securityArchive: SecurityArchiveLike | undefined\n}\n\n// A list of known security selectors that rely on\n// data from the security-archive in order to work\nconst securitySelectors = new Set([\n ':abandoned',\n ':confused',\n ':cve',\n ':debug',\n ':deprecated',\n ':dynamic',\n ':entropic',\n ':env',\n ':eval',\n ':fs',\n ':license',\n ':malware',\n ':minified',\n ':native',\n ':network',\n ':obfuscated',\n ':scripts',\n ':sev',\n ':severity',\n ':shell',\n ':shrinkwrap',\n ':squat',\n ':suspicious',\n ':tracker',\n ':trivial',\n ':undesirable',\n ':unknown',\n ':unmaintained',\n ':unpopular',\n ':unstable',\n])\n\nexport class Query {\n #cache: Map<string, QueryResponse>\n #graph: GraphLike\n #specOptions: SpecOptions\n #securityArchive: SecurityArchiveLike | undefined\n\n /**\n * Helper method to determine if a given query string is using any of\n * the known security selectors. This is useful so that operations can\n * skip hydrating the security archive if it's not needed.\n */\n static hasSecuritySelectors(query: string): boolean {\n for (const selector of securitySelectors) {\n if (query.includes(selector)) {\n return true\n }\n }\n return false\n }\n\n constructor({ graph, specOptions, securityArchive }: QueryOptions) {\n this.#cache = new Map()\n this.#graph = graph\n this.#specOptions = specOptions\n this.#securityArchive = securityArchive\n }\n\n /**\n * Search the graph for nodes and edges that match the given query.\n */\n async search(\n query: string,\n signal?: AbortSignal,\n ): Promise<QueryResponse> {\n if (typeof query !== 'string') {\n throw new TypeError(\n 'Query search argument needs to be a string',\n )\n }\n\n if (!query) return { edges: [], nodes: [] }\n\n const cachedResult = this.#cache.get(query)\n if (cachedResult) {\n return cachedResult\n }\n\n const nodes = new Set<NodeLike>(\n Array.from(this.#graph.nodes.values()),\n )\n const edges = new Set<EdgeLike>(Array.from(this.#graph.edges))\n\n // builds initial state and walks over it,\n // retrieving the collected result\n const { collect } = await walk({\n cancellable: async () => {\n await new Promise(resolve => {\n setTimeout(resolve, 0)\n })\n signal?.throwIfAborted()\n },\n current: postcssSelectorParser().astSync(query),\n initial: {\n nodes: new Set(nodes),\n edges: new Set(edges),\n },\n collect: {\n nodes: new Set<NodeLike>(),\n edges: new Set<EdgeLike>(),\n },\n partial: { nodes, edges },\n signal,\n securityArchive: this.#securityArchive,\n specOptions: this.#specOptions,\n walk,\n })\n\n const res: QueryResponse = {\n edges: Array.from(collect.edges),\n nodes: Array.from(collect.nodes),\n }\n this.#cache.set(query, res)\n return res\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abandoned.d.ts","sourceRoot":"","sources":["../../../src/pseudo/abandoned.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,SAAS,0FAGrB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createSecuritySelectorFilter } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Filters out any node that does not have a **missingAuthor** report alert.
|
|
4
|
+
*/
|
|
5
|
+
export const abandoned = createSecuritySelectorFilter('abandoned', 'missingAuthor');
|
|
6
|
+
//# sourceMappingURL=abandoned.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abandoned.js","sourceRoot":"","sources":["../../../src/pseudo/abandoned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,4BAA4B,CACnD,WAAW,EACX,eAAe,CAChB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **missingAuthor** report alert.\n */\nexport const abandoned = createSecuritySelectorFilter(\n 'abandoned',\n 'missingAuthor',\n)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confused.d.ts","sourceRoot":"","sources":["../../../src/pseudo/confused.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ,0FAGpB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createSecuritySelectorFilter } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Filters out any node that does not have a **manifestConfusion** report alert.
|
|
4
|
+
*/
|
|
5
|
+
export const confused = createSecuritySelectorFilter('confused', 'manifestConfusion');
|
|
6
|
+
//# sourceMappingURL=confused.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confused.js","sourceRoot":"","sources":["../../../src/pseudo/confused.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAClD,UAAU,EACV,mBAAmB,CACpB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **manifestConfusion** report alert.\n */\nexport const confused = createSecuritySelectorFilter(\n 'confused',\n 'manifestConfusion',\n)\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParserState, PostcssNode } from '../types.ts';
|
|
2
|
+
export type CveInternals = {
|
|
3
|
+
cveId: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const parseInternals: (nodes: PostcssNode[]) => CveInternals;
|
|
6
|
+
/**
|
|
7
|
+
* Filters out any node that does not have a CVE alert with the specified CVE ID.
|
|
8
|
+
*/
|
|
9
|
+
export declare const cve: (state: ParserState) => Promise<ParserState>;
|
|
10
|
+
//# sourceMappingURL=cve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cve.d.ts","sourceRoot":"","sources":["../../../src/pseudo/cve.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,YAuBF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,UAAiB,WAAW,yBAiC3C,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
|
|
3
|
+
import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
|
|
4
|
+
export const parseInternals = (nodes) => {
|
|
5
|
+
let cveId = '';
|
|
6
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
7
|
+
cveId = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
8
|
+
.value);
|
|
9
|
+
}
|
|
10
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
11
|
+
cveId = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value;
|
|
12
|
+
}
|
|
13
|
+
if (!cveId) {
|
|
14
|
+
throw error('Expected a CVE ID', {
|
|
15
|
+
found: asPostcssNodeWithChildren(nodes[0]).nodes[0],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return { cveId };
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Filters out any node that does not have a CVE alert with the specified CVE ID.
|
|
22
|
+
*/
|
|
23
|
+
export const cve = async (state) => {
|
|
24
|
+
if (!state.securityArchive) {
|
|
25
|
+
throw new Error('Missing security archive while trying to parse ' +
|
|
26
|
+
'the :cve security selector');
|
|
27
|
+
}
|
|
28
|
+
let internals;
|
|
29
|
+
try {
|
|
30
|
+
internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw error('Failed to parse :cve selector', { cause: err });
|
|
34
|
+
}
|
|
35
|
+
const { cveId } = internals;
|
|
36
|
+
for (const node of state.partial.nodes) {
|
|
37
|
+
const report = state.securityArchive.get(node.id);
|
|
38
|
+
const exclude = !report?.alerts.some(alert => alert.props.cveId.trim().toLowerCase() ===
|
|
39
|
+
cveId.trim().toLowerCase());
|
|
40
|
+
if (exclude) {
|
|
41
|
+
removeNode(state, node);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
removeDanglingEdges(state);
|
|
45
|
+
return state;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=cve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cve.js","sourceRoot":"","sources":["../../../src/pseudo/cve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,GACV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAMrB,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAoB,EACN,EAAE;IAChB,IAAI,KAAK,GAAG,EAAE,CAAA;IAEd,IAAI,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,GAAG,YAAY,CAClB,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aACvD,KAAK,CACT,CAAA;IACH,CAAC;SAAM,IACL,SAAS,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACvD,CAAC;QACD,KAAK,GAAG,SAAS,CACf,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAC7C,CAAC,KAAK,CAAA;IACT,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,KAAK,CAAC,mBAAmB,EAAE;YAC/B,KAAK,EAAE,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;SACpD,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAA;AAClB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,EAAE,KAAkB,EAAE,EAAE;IAC9C,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,iDAAiD;YAC/C,4BAA4B,CAC/B,CAAA;IACH,CAAC;IAED,IAAI,SAAS,CAAA;IACb,IAAI,CAAC;QACH,SAAS,GAAG,cAAc,CACxB,yBAAyB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,CAC/C,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,KAAK,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAA;IAC9D,CAAC;IAED,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAA;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAClC,KAAK,CAAC,EAAE,CACN,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE;YACtC,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAC7B,CAAA;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type CveInternals = {\n cveId: string\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): CveInternals => {\n let cveId = ''\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n cveId = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n cveId = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n ).value\n }\n\n if (!cveId) {\n throw error('Expected a CVE ID', {\n found: asPostcssNodeWithChildren(nodes[0]).nodes[0],\n })\n }\n\n return { cveId }\n}\n\n/**\n * Filters out any node that does not have a CVE alert with the specified CVE ID.\n */\nexport const cve = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :cve security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :cve selector', { cause: err })\n }\n\n const { cveId } = internals\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(\n alert =>\n alert.props.cveId.trim().toLowerCase() ===\n cveId.trim().toLowerCase(),\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ParserState, PostcssNode } from '../types.ts';
|
|
2
|
+
export type CweInternals = {
|
|
3
|
+
cweId: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const parseInternals: (nodes: PostcssNode[]) => CweInternals;
|
|
6
|
+
/**
|
|
7
|
+
* Filters out any node that does not have a CWE alert with the specified CWE ID.
|
|
8
|
+
*/
|
|
9
|
+
export declare const cwe: (state: ParserState) => Promise<ParserState>;
|
|
10
|
+
//# sourceMappingURL=cwe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cwe.d.ts","sourceRoot":"","sources":["../../../src/pseudo/cwe.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAO3D,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,cAAc,UAClB,WAAW,EAAE,KACnB,YAuBF,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,GAAG,UAAiB,WAAW,yBAkC3C,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { asPostcssNodeWithChildren, asStringNode, asTagNode, isStringNode, isTagNode, } from "../types.js";
|
|
3
|
+
import { removeDanglingEdges, removeNode, removeQuotes, } from "./helpers.js";
|
|
4
|
+
export const parseInternals = (nodes) => {
|
|
5
|
+
let cweId = '';
|
|
6
|
+
if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
7
|
+
cweId = removeQuotes(asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])
|
|
8
|
+
.value);
|
|
9
|
+
}
|
|
10
|
+
else if (isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {
|
|
11
|
+
cweId = asTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0]).value;
|
|
12
|
+
}
|
|
13
|
+
if (!cweId) {
|
|
14
|
+
throw error('Expected a CWE ID', {
|
|
15
|
+
found: asPostcssNodeWithChildren(nodes[0]).nodes[0],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return { cweId };
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Filters out any node that does not have a CWE alert with the specified CWE ID.
|
|
22
|
+
*/
|
|
23
|
+
export const cwe = async (state) => {
|
|
24
|
+
if (!state.securityArchive) {
|
|
25
|
+
throw new Error('Missing security archive while trying to parse ' +
|
|
26
|
+
'the :cwe security selector');
|
|
27
|
+
}
|
|
28
|
+
let internals;
|
|
29
|
+
try {
|
|
30
|
+
internals = parseInternals(asPostcssNodeWithChildren(state.current).nodes);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
throw error('Failed to parse :cwe selector', { cause: err });
|
|
34
|
+
}
|
|
35
|
+
const { cweId } = internals;
|
|
36
|
+
for (const node of state.partial.nodes) {
|
|
37
|
+
const report = state.securityArchive.get(node.id);
|
|
38
|
+
const exclude = !report?.alerts.some(alert => alert.props.cwes.some(cwe => cwe.id.trim().toLowerCase() === cweId.trim().toLowerCase()));
|
|
39
|
+
if (exclude) {
|
|
40
|
+
removeNode(state, node);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
removeDanglingEdges(state);
|
|
44
|
+
return state;
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=cwe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cwe.js","sourceRoot":"","sources":["../../../src/pseudo/cwe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,yBAAyB,EACzB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,SAAS,GACV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,cAAc,CAAA;AAMrB,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAoB,EACN,EAAE;IAChB,IAAI,KAAK,GAAG,EAAE,CAAA;IAEd,IAAI,YAAY,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,GAAG,YAAY,CAClB,YAAY,CAAC,yBAAyB,CAAC,KAAK,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AAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAC3C,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CACnB,GAAG,CAAC,EAAE,CACJ,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAC7D,CACF,CAAA;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;IAED,mBAAmB,CAAC,KAAK,CAAC,CAAA;IAE1B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n asPostcssNodeWithChildren,\n asStringNode,\n asTagNode,\n isStringNode,\n isTagNode,\n} from '../types.ts'\nimport type { ParserState, PostcssNode } from '../types.ts'\nimport {\n removeDanglingEdges,\n removeNode,\n removeQuotes,\n} from './helpers.ts'\n\nexport type CweInternals = {\n cweId: string\n}\n\nexport const parseInternals = (\n nodes: PostcssNode[],\n): CweInternals => {\n let cweId = ''\n\n if (isStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])) {\n cweId = removeQuotes(\n asStringNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n .value,\n )\n } else if (\n isTagNode(asPostcssNodeWithChildren(nodes[0]).nodes[0])\n ) {\n cweId = asTagNode(\n asPostcssNodeWithChildren(nodes[0]).nodes[0],\n ).value\n }\n\n if (!cweId) {\n throw error('Expected a CWE ID', {\n found: asPostcssNodeWithChildren(nodes[0]).nodes[0],\n })\n }\n\n return { cweId }\n}\n\n/**\n * Filters out any node that does not have a CWE alert with the specified CWE ID.\n */\nexport const cwe = async (state: ParserState) => {\n if (!state.securityArchive) {\n throw new Error(\n 'Missing security archive while trying to parse ' +\n 'the :cwe security selector',\n )\n }\n\n let internals\n try {\n internals = parseInternals(\n asPostcssNodeWithChildren(state.current).nodes,\n )\n } catch (err) {\n throw error('Failed to parse :cwe selector', { cause: err })\n }\n\n const { cweId } = internals\n for (const node of state.partial.nodes) {\n const report = state.securityArchive.get(node.id)\n const exclude = !report?.alerts.some(alert =>\n alert.props.cwes.some(\n cwe =>\n cwe.id.trim().toLowerCase() === cweId.trim().toLowerCase(),\n ),\n )\n if (exclude) {\n removeNode(state, node)\n }\n }\n\n removeDanglingEdges(state)\n\n return state\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../src/pseudo/debug.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,KAAK,0FAGjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../../src/pseudo/debug.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,4BAA4B,CAC/C,OAAO,EACP,aAAa,CACd,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **debugAccess** report alert.\n */\nexport const debug = createSecuritySelectorFilter(\n 'debug',\n 'debugAccess',\n)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecated.d.ts","sourceRoot":"","sources":["../../../src/pseudo/deprecated.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,UAAU,0FAGtB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createSecuritySelectorFilter } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Filters out any node that does not have a **deprecated** report alert.
|
|
4
|
+
*/
|
|
5
|
+
export const deprecated = createSecuritySelectorFilter('deprecated', 'deprecated');
|
|
6
|
+
//# sourceMappingURL=deprecated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecated.js","sourceRoot":"","sources":["../../../src/pseudo/deprecated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CACpD,YAAY,EACZ,YAAY,CACb,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **deprecated** report alert.\n */\nexport const deprecated = createSecuritySelectorFilter(\n 'deprecated',\n 'deprecated',\n)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic.d.ts","sourceRoot":"","sources":["../../../src/pseudo/dynamic.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO,0FAGnB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createSecuritySelectorFilter } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Filters out any node that does not have a **dynamicRequire** report alert.
|
|
4
|
+
*/
|
|
5
|
+
export const dynamic = createSecuritySelectorFilter('dynamic', 'dynamicRequire');
|
|
6
|
+
//# sourceMappingURL=dynamic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dynamic.js","sourceRoot":"","sources":["../../../src/pseudo/dynamic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,4BAA4B,CACjD,SAAS,EACT,gBAAgB,CACjB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **dynamicRequire** report alert.\n */\nexport const dynamic = createSecuritySelectorFilter(\n 'dynamic',\n 'dynamicRequire',\n)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropic.d.ts","sourceRoot":"","sources":["../../../src/pseudo/entropic.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ,0FAGpB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createSecuritySelectorFilter } from "./helpers.js";
|
|
2
|
+
/**
|
|
3
|
+
* Filters out any node that does not have a **highEntropyStrings** report alert.
|
|
4
|
+
*/
|
|
5
|
+
export const entropic = createSecuritySelectorFilter('entropic', 'highEntropyStrings');
|
|
6
|
+
//# sourceMappingURL=entropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entropic.js","sourceRoot":"","sources":["../../../src/pseudo/entropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,4BAA4B,CAClD,UAAU,EACV,oBAAoB,CACrB,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **highEntropyStrings** report alert.\n */\nexport const entropic = createSecuritySelectorFilter(\n 'entropic',\n 'highEntropyStrings',\n)\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/pseudo/env.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,GAAG,0FAAiD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/pseudo/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,4BAA4B,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **envVars** report alert.\n */\nexport const env = createSecuritySelectorFilter('env', 'envVars')\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../../src/pseudo/eval.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,UAAU,0FAGtB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eval.js","sourceRoot":"","sources":["../../../src/pseudo/eval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,4BAA4B,CACpD,MAAM,EACN,UAAU,CACX,CAAA","sourcesContent":["import { createSecuritySelectorFilter } from './helpers.ts'\n\n/**\n * Filters out any node that does not have a **usesEval** report alert.\n */\nexport const evalParser = createSecuritySelectorFilter(\n 'eval',\n 'usesEval',\n)\n"]}
|