@andesyte-oss/security-rules 0.1.3 → 0.2.0

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/dist/index.d.ts CHANGED
@@ -4,8 +4,18 @@
4
4
  * no network request to any rule registry.
5
5
  */
6
6
  export declare function rulesDir(): string;
7
- export declare function rulePaths(): string[];
7
+ export declare function rulePaths(options?: {
8
+ reviewSinks?: boolean;
9
+ }): string[];
8
10
  export declare const RULESET_NAME = "andesyte-local";
11
+ /**
12
+ * The sink-review rule family, owned here where the rule ids are authored.
13
+ * Adapters classify findings through this helper instead of string-matching
14
+ * the prefix themselves, so renaming the family or adding a second review
15
+ * pack is a one-package change.
16
+ */
17
+ export declare const SINK_REVIEW_RULE_PREFIX = "ai.sink-review.";
18
+ export declare function isSinkReviewRuleId(ruleId: string | undefined): boolean;
9
19
  export declare const RULESET_VERSION: string;
10
20
  export interface RulesetDescriptor {
11
21
  name: string;
@@ -15,4 +25,6 @@ export interface RulesetDescriptor {
15
25
  languageExtensions: Readonly<Record<string, readonly string[]>>;
16
26
  }
17
27
  /** Complete descriptor consumed by scanner adapters. */
18
- export declare function ruleset(): RulesetDescriptor;
28
+ export declare function ruleset(options?: {
29
+ reviewSinks?: boolean;
30
+ }): RulesetDescriptor;
package/dist/index.js CHANGED
@@ -16,14 +16,27 @@ export function rulesDir() {
16
16
  }
17
17
  throw new Error("packaged rules directory not found");
18
18
  }
19
- export function rulePaths() {
19
+ export function rulePaths(options = {}) {
20
20
  const dir = rulesDir();
21
- return readdirSync(dir)
21
+ const files = readdirSync(dir)
22
22
  .filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))
23
23
  .sort()
24
24
  .map((f) => join(dir, f));
25
+ if (options.reviewSinks)
26
+ files.push(join(dir, "review", "unsafe-sinks-js.yml"));
27
+ return files;
25
28
  }
26
29
  export const RULESET_NAME = "andesyte-local";
30
+ /**
31
+ * The sink-review rule family, owned here where the rule ids are authored.
32
+ * Adapters classify findings through this helper instead of string-matching
33
+ * the prefix themselves, so renaming the family or adding a second review
34
+ * pack is a one-package change.
35
+ */
36
+ export const SINK_REVIEW_RULE_PREFIX = "ai.sink-review.";
37
+ export function isSinkReviewRuleId(ruleId) {
38
+ return typeof ruleId === "string" && ruleId.startsWith(SINK_REVIEW_RULE_PREFIX);
39
+ }
27
40
  function packageVersion() {
28
41
  try {
29
42
  const manifest = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
@@ -35,11 +48,11 @@ function packageVersion() {
35
48
  }
36
49
  export const RULESET_VERSION = packageVersion();
37
50
  /** Complete descriptor consumed by scanner adapters. */
38
- export function ruleset() {
51
+ export function ruleset(options = {}) {
39
52
  return {
40
53
  name: RULESET_NAME,
41
54
  version: RULESET_VERSION,
42
- rulePaths: rulePaths(),
55
+ rulePaths: rulePaths(options),
43
56
  languageExtensions: {},
44
57
  };
45
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andesyte-oss/security-rules",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Andesyte curated Semgrep security rules, shipped as packaged local files (no registry fetch).",
5
5
  "homepage": "https://andesyte.com",
6
6
  "author": "Andesyte <lewis@andesyte.com>",
@@ -72,6 +72,8 @@ rules:
72
72
  - pattern: $X.choices[0].message.content
73
73
  - pattern: $X.choices[0].delta.content
74
74
  - pattern: $X.content[0].text
75
+ - pattern: $X.response.text()
76
+ - pattern: $X.models.generateContent(...)
75
77
  - pattern: generateText(...)
76
78
  - pattern: streamText(...)
77
79
  pattern-sanitizers:
@@ -201,6 +203,8 @@ rules:
201
203
  - pattern: $X.choices[0].message.content
202
204
  - pattern: $X.choices[0].delta.content
203
205
  - pattern: $X.content[0].text
206
+ - pattern: $X.response.text()
207
+ - pattern: $X.models.generateContent(...)
204
208
  - pattern: generateText(...)
205
209
  - pattern: streamText(...)
206
210
  pattern-sinks:
@@ -219,3 +223,31 @@ rules:
219
223
  - pattern: "$CP.spawnSync($CMD, $ARGS, { ..., shell: true, ... })"
220
224
  - pattern: "spawnSync($CMD, $ARGS, { ..., shell: true, ... })"
221
225
  - focus-metavariable: $CMD
226
+
227
+ - id: ai.insecure-output-handling.eval-llm-response-js
228
+ message: >-
229
+ Model output reaches dynamic JavaScript execution. Treat generated code as
230
+ untrusted and do not execute it with eval or Function.
231
+ severity: ERROR
232
+ languages: [typescript, javascript]
233
+ mode: taint
234
+ metadata:
235
+ cwe: "CWE-94: Improper Control of Generation of Code"
236
+ owasp: "LLM02:2026 Insecure Output Handling"
237
+ impact: HIGH
238
+ pattern-sources:
239
+ - pattern-either:
240
+ - pattern: $X.choices[0].message.content
241
+ - pattern: $X.choices[0].delta.content
242
+ - pattern: $X.content[0].text
243
+ - pattern: $X.response.text()
244
+ - pattern: $X.models.generateContent(...)
245
+ - pattern: generateText(...)
246
+ - pattern: streamText(...)
247
+ pattern-sinks:
248
+ - patterns:
249
+ - pattern-either:
250
+ - pattern: eval($CODE)
251
+ - pattern: Function($CODE)
252
+ - pattern: new Function($CODE)
253
+ - focus-metavariable: $CODE
@@ -0,0 +1,34 @@
1
+ rules:
2
+ - id: ai.sink-review.dynamic-code-js
3
+ message: >-
4
+ REVIEW REQUIRED: non-literal data reaches dynamic JavaScript execution.
5
+ Its origin is unknown to this check.
6
+ severity: WARNING
7
+ languages: [typescript, javascript]
8
+ metadata:
9
+ cwe: "CWE-94: Improper Control of Generation of Code"
10
+ analysis_kind: sink-review
11
+ patterns:
12
+ - pattern-either:
13
+ - pattern: eval($CODE)
14
+ - pattern: Function($CODE)
15
+ - pattern: new Function($CODE)
16
+ - pattern-not: eval("...")
17
+ - pattern-not: Function("...")
18
+ - pattern-not: new Function("...")
19
+ - id: ai.sink-review.raw-html-js
20
+ message: >-
21
+ REVIEW REQUIRED: non-literal data reaches a raw HTML sink. Its origin is
22
+ unknown to this check.
23
+ severity: WARNING
24
+ languages: [typescript, javascript]
25
+ metadata:
26
+ cwe: "CWE-79: Cross-site Scripting"
27
+ analysis_kind: sink-review
28
+ patterns:
29
+ - pattern-either:
30
+ - pattern: $EL.innerHTML = $HTML
31
+ - pattern: $EL.outerHTML = $HTML
32
+ - pattern: $EL.insertAdjacentHTML($POS, $HTML)
33
+ - pattern: |
34
+ <$TAG dangerouslySetInnerHTML={{ __html: $HTML }} />