@intentius/chant-lexicon-gitlab 0.1.23 → 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.
Files changed (77) hide show
  1. package/dist/integrity.json +24 -4
  2. package/dist/manifest.json +1 -1
  3. package/dist/rules/wgl029.ts +59 -0
  4. package/dist/rules/wgl030.ts +48 -0
  5. package/dist/rules/wgl031.ts +37 -0
  6. package/dist/rules/wgl032.ts +68 -0
  7. package/dist/rules/wgl033.ts +38 -0
  8. package/dist/rules/wgl034.ts +42 -0
  9. package/dist/rules/wgl035.ts +44 -0
  10. package/dist/rules/wgl036.ts +44 -0
  11. package/dist/rules/wgl037.ts +47 -0
  12. package/dist/rules/wgl038.ts +48 -0
  13. package/dist/rules/wgl039.ts +41 -0
  14. package/dist/rules/wgl040.ts +42 -0
  15. package/dist/rules/wgl041.ts +57 -0
  16. package/dist/rules/wgl042.ts +46 -0
  17. package/dist/rules/wgl043.ts +45 -0
  18. package/dist/rules/wgl044.ts +41 -0
  19. package/dist/rules/wgl045.ts +57 -0
  20. package/dist/rules/wgl046.ts +43 -0
  21. package/dist/rules/wgl047.ts +41 -0
  22. package/dist/rules/wgl048.ts +37 -0
  23. package/dist/rules/yaml-helpers.ts +214 -0
  24. package/dist/skills/chant-gitlab-migrate.md +10 -0
  25. package/package.json +1 -1
  26. package/src/codegen/docs.ts +130 -0
  27. package/src/lint/post-synth/wgl029.test.ts +77 -0
  28. package/src/lint/post-synth/wgl029.ts +59 -0
  29. package/src/lint/post-synth/wgl030.test.ts +57 -0
  30. package/src/lint/post-synth/wgl030.ts +48 -0
  31. package/src/lint/post-synth/wgl031.test.ts +66 -0
  32. package/src/lint/post-synth/wgl031.ts +37 -0
  33. package/src/lint/post-synth/wgl032.test.ts +53 -0
  34. package/src/lint/post-synth/wgl032.ts +68 -0
  35. package/src/lint/post-synth/wgl033.test.ts +58 -0
  36. package/src/lint/post-synth/wgl033.ts +38 -0
  37. package/src/lint/post-synth/wgl034.test.ts +60 -0
  38. package/src/lint/post-synth/wgl034.ts +42 -0
  39. package/src/lint/post-synth/wgl035.test.ts +42 -0
  40. package/src/lint/post-synth/wgl035.ts +44 -0
  41. package/src/lint/post-synth/wgl036.test.ts +49 -0
  42. package/src/lint/post-synth/wgl036.ts +44 -0
  43. package/src/lint/post-synth/wgl037.test.ts +45 -0
  44. package/src/lint/post-synth/wgl037.ts +47 -0
  45. package/src/lint/post-synth/wgl038.test.ts +54 -0
  46. package/src/lint/post-synth/wgl038.ts +48 -0
  47. package/src/lint/post-synth/wgl039.test.ts +39 -0
  48. package/src/lint/post-synth/wgl039.ts +41 -0
  49. package/src/lint/post-synth/wgl040.test.ts +48 -0
  50. package/src/lint/post-synth/wgl040.ts +42 -0
  51. package/src/lint/post-synth/wgl041.test.ts +49 -0
  52. package/src/lint/post-synth/wgl041.ts +57 -0
  53. package/src/lint/post-synth/wgl042.test.ts +45 -0
  54. package/src/lint/post-synth/wgl042.ts +46 -0
  55. package/src/lint/post-synth/wgl043.test.ts +43 -0
  56. package/src/lint/post-synth/wgl043.ts +45 -0
  57. package/src/lint/post-synth/wgl044.test.ts +46 -0
  58. package/src/lint/post-synth/wgl044.ts +41 -0
  59. package/src/lint/post-synth/wgl045.test.ts +48 -0
  60. package/src/lint/post-synth/wgl045.ts +57 -0
  61. package/src/lint/post-synth/wgl046.test.ts +67 -0
  62. package/src/lint/post-synth/wgl046.ts +43 -0
  63. package/src/lint/post-synth/wgl047.test.ts +40 -0
  64. package/src/lint/post-synth/wgl047.ts +41 -0
  65. package/src/lint/post-synth/wgl048.test.ts +56 -0
  66. package/src/lint/post-synth/wgl048.ts +37 -0
  67. package/src/lint/post-synth/yaml-helpers.ts +214 -0
  68. package/src/lint/rules/data/known-include-sources.ts +41 -0
  69. package/src/lint/rules/data/untrusted-variables.ts +31 -0
  70. package/src/migrate/from-github/diagnostics.ts +18 -0
  71. package/src/migrate/from-github/index.ts +20 -1
  72. package/src/migrate/from-github/provenance.ts +28 -0
  73. package/src/migrate/from-github/rules.ts +7 -0
  74. package/src/migrate/from-github/security.test.ts +98 -0
  75. package/src/migrate/from-github/security.ts +208 -0
  76. package/src/plugin.test.ts +21 -1
  77. package/src/skills/chant-gitlab-migrate.md +10 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "b4d7feeb0492db60bb09ef9a5ab36736e3f787d12a3ed3244aa54bc71679c980",
4
+ "manifest.json": "9bfe8386c57d5e1081398a3128f8c1ddde259e0ada0d4ec5e2ea4fafc3301eb1",
5
5
  "meta.json": "931fc3246a55645b1493080bbeb160e5d205e42349e8bdca96ca243adb5f0da3",
6
6
  "types/index.d.ts": "5cd2e99f135a929b72bdd822d00d780d39b1cd407ba0cfb3d511c7ac9d667b58",
7
7
  "rules/artifact-no-expiry.ts": "3f3cabf9792cbf8207e53a25f506715466b19ec25e9c3b4d0d77fed6b2eb4542",
@@ -27,10 +27,30 @@
27
27
  "rules/wgl026.ts": "b7d9f075aa8fc9623e28745b68c2368c223c2899641cbb7796952018717dcee5",
28
28
  "rules/wgl027.ts": "1ff29b9101a268c58756593b0d86396b557a79527b5dc390c190ae224c12597a",
29
29
  "rules/wgl028.ts": "f1c64eda25e2ad8da634d64a397f877a46ae8327713db5cf3193882bb9b96453",
30
- "rules/yaml-helpers.ts": "f2322530a7fd812e482c5a7df05d0d05787b207574b67b811776786e00fd3e18",
30
+ "rules/wgl029.ts": "f06d36689d5e5649ae4465ea3b45e6e5e797223f246c45b7cb4dab7bef09ab05",
31
+ "rules/wgl030.ts": "6acd43eadebde694676257de0a1b1b8477f3acd8f4db3380a987fafb8d65b68f",
32
+ "rules/wgl031.ts": "b59221bec34c2f17c83db1a552e9acbd843d9710cc71aff1f13137f373d864dd",
33
+ "rules/wgl032.ts": "9cbb16c5fde4d5bc6161e3db5b8523272f069fd703e11530db46670ac8805e1d",
34
+ "rules/wgl033.ts": "74e23b9582d0431320b81b23686ffd0aa07a9b23831acd55764b4695d1a68fb2",
35
+ "rules/wgl034.ts": "a973179ae0f2e665e08a4b482a9388482f454ce5480c725cc640fe39c738ef60",
36
+ "rules/wgl035.ts": "3ecf8185d857046435f6a1a33e69061c27ab2aad1758673c28f591a6eca2b08a",
37
+ "rules/wgl036.ts": "fea9314e973434e17ce6459dda537e3138703f461a7f5cfe81290a83ed038e0b",
38
+ "rules/wgl037.ts": "83c14f97f9df2ade526a13be17a2f7c39429d23d426b5a7a9735d67d00f1d137",
39
+ "rules/wgl038.ts": "947599eb5ed9d505b23b4fe6dc0e9ec006e325dc34da9b3e1a3caf716a9e327c",
40
+ "rules/wgl039.ts": "5464a00d61aced70e9b5b35d642b9cb3704c46cd045f20d3e5da7e02176b704e",
41
+ "rules/wgl040.ts": "05b6c18488b1c48cba26e709ef5e0b97a6416b6f2d95d7a54e53951156258778",
42
+ "rules/wgl041.ts": "feb34fccd401fea58441123367701e7bd3acc84e9c36b72cd50fe812f33f6bea",
43
+ "rules/wgl042.ts": "0af844881fea0011442f6d5f8677cefffbc24c0482a0e7328eb756d08e094758",
44
+ "rules/wgl043.ts": "0191bd9e93ff6ad3176177cfca2431bff47c166f2f5588b12a4c4115ff531954",
45
+ "rules/wgl044.ts": "d8c28f461e936d87c26f7bab819093715b170afa56dea22990acfe3447814d11",
46
+ "rules/wgl045.ts": "7eb13fe8d263a3f65e5b80c1dffe74e09eac7155e4c2d21df552a6b169099da0",
47
+ "rules/wgl046.ts": "bbd8f5075aa390db546f5e787ce542f31a9d5eb031578780480e770cd86f9b5b",
48
+ "rules/wgl047.ts": "e6dba6a0c6c042e90a200859e52a0da28c56ce52705e147760eca0a0a37c3255",
49
+ "rules/wgl048.ts": "810590da4e7eaf70a6332ae247dbd34e000e2af57c89d3bd5a19bb2a923fcbb1",
50
+ "rules/yaml-helpers.ts": "5835982d5d088eb4788ebad8160b181bfdb6fc94d546eabee90a4c278a913988",
31
51
  "skills/chant-gitlab.md": "1e26a0c50ea891423479bd7fec3bc133f9185727c4a3eaadd525d7e7436056b6",
32
- "skills/chant-gitlab-migrate.md": "9402ed4fcfd25971cf72f8f02a93c43aadfed3b83876081b92711562ce1bdc34",
52
+ "skills/chant-gitlab-migrate.md": "4853d04980560b379e5b0f7267dcb0a1e5d5879cb9e9931681ce76b2a5fe69d8",
33
53
  "skills/chant-gitlab-patterns.md": "cefda1b656f222293d16381dfbf452b2b376b545a69f62e55dc38907fe8aa7fa"
34
54
  },
35
- "composite": "7a75ca0fe3e447809c10811c6bc8c80afa64ab238614c0a2ba53fad38048ff85"
55
+ "composite": "26728547d1b80d6bd7ac26734b9bc312b73971bc8a3238dcde789a85e1d83541"
36
56
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitlab",
3
- "version": "0.1.23",
3
+ "version": "0.2.0",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "GitLab",
6
6
  "intrinsics": [
@@ -0,0 +1,59 @@
1
+ /**
2
+ * WGL029: Unpinned include:project / component Reference
3
+ *
4
+ * Flags an `include:project` or CI/CD `component:` resolved by a moving ref — a
5
+ * branch, no `ref:` at all (defaults to the project's default branch), or a
6
+ * floating component version — instead of a pinned tag or commit SHA. A
7
+ * repointed ref turns the included configuration into a supply-chain entry point.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractIncludes, isPinnedRef } from "./yaml-helpers";
12
+
13
+ export const wgl029: PostSynthCheck = {
14
+ id: "WGL029",
15
+ description: "include:project / component resolved by a moving ref instead of a pinned tag or SHA",
16
+
17
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
18
+ const diagnostics: PostSynthDiagnostic[] = [];
19
+
20
+ for (const [, output] of ctx.outputs) {
21
+ const yaml = getPrimaryOutput(output);
22
+ for (const entry of extractIncludes(yaml)) {
23
+ if (entry.kind === "project") {
24
+ if (!entry.ref) {
25
+ diagnostics.push({
26
+ checkId: "WGL029",
27
+ severity: "warning",
28
+ message: `include:project "${entry.value}" has no ref: and resolves to the project's default branch (a moving target). Pin it to a tag or commit SHA.`,
29
+ entity: entry.value,
30
+ lexicon: "gitlab",
31
+ });
32
+ } else if (!isPinnedRef(entry.ref)) {
33
+ diagnostics.push({
34
+ checkId: "WGL029",
35
+ severity: "warning",
36
+ message: `include:project "${entry.value}" is pinned to the moving ref "${entry.ref}". Pin it to a tag or commit SHA.`,
37
+ entity: entry.value,
38
+ lexicon: "gitlab",
39
+ });
40
+ }
41
+ } else if (entry.kind === "component") {
42
+ const at = entry.value.lastIndexOf("@");
43
+ const version = at === -1 ? "" : entry.value.slice(at + 1);
44
+ if (!version || !isPinnedRef(version)) {
45
+ diagnostics.push({
46
+ checkId: "WGL029",
47
+ severity: "warning",
48
+ message: `component "${entry.value}" uses ${version ? `the moving version "${version}"` : "no pinned version"}. Pin it to a released version tag or commit SHA.`,
49
+ entity: entry.value,
50
+ lexicon: "gitlab",
51
+ });
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ return diagnostics;
58
+ },
59
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * WGL030: Mutable or Insecure include:remote
3
+ *
4
+ * Flags `include:remote` URLs that are fetched over HTTP (no transport
5
+ * integrity) or over HTTPS but inherently mutable (a raw URL can be repointed
6
+ * at any time). Prefer `include:project` pinned to a tag/SHA, or a pinned
7
+ * component, over a remote URL. Generalizes WGL017 (non-HTTPS) to includes.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractIncludes } from "./yaml-helpers";
12
+
13
+ export const wgl030: PostSynthCheck = {
14
+ id: "WGL030",
15
+ description: "include:remote is insecure (HTTP) or mutable",
16
+
17
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
18
+ const diagnostics: PostSynthDiagnostic[] = [];
19
+
20
+ for (const [, output] of ctx.outputs) {
21
+ const yaml = getPrimaryOutput(output);
22
+ for (const entry of extractIncludes(yaml)) {
23
+ const isRemote = entry.kind === "remote" || (entry.kind === "string" && /^https?:\/\//.test(entry.value));
24
+ if (!isRemote) continue;
25
+
26
+ if (/^http:\/\//.test(entry.value)) {
27
+ diagnostics.push({
28
+ checkId: "WGL030",
29
+ severity: "error",
30
+ message: `include:remote "${entry.value}" is fetched over HTTP — an attacker on the network can swap the included config. Use HTTPS, and prefer a pinned include:project or component.`,
31
+ entity: entry.value,
32
+ lexicon: "gitlab",
33
+ });
34
+ } else {
35
+ diagnostics.push({
36
+ checkId: "WGL030",
37
+ severity: "warning",
38
+ message: `include:remote "${entry.value}" is a mutable URL — its contents can change after review. Prefer include:project pinned to a tag/SHA, or a pinned component.`,
39
+ entity: entry.value,
40
+ lexicon: "gitlab",
41
+ });
42
+ }
43
+ }
44
+ }
45
+
46
+ return diagnostics;
47
+ },
48
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * WGL031: Container Image Without an Immutable Digest
3
+ *
4
+ * Flags `image:` and `services:` references that are not pinned to an immutable
5
+ * `@sha256:` digest. A mutable tag can be repointed to a different image after
6
+ * review. Images built from a variable (e.g. `$CI_REGISTRY_IMAGE:tag`) are
7
+ * skipped — their concrete reference is not knowable from the static config.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractImageRefs } from "./yaml-helpers";
12
+
13
+ export const wgl031: PostSynthCheck = {
14
+ id: "WGL031",
15
+ description: "Container image not pinned to an immutable digest",
16
+
17
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
18
+ const diagnostics: PostSynthDiagnostic[] = [];
19
+
20
+ for (const [, output] of ctx.outputs) {
21
+ const yaml = getPrimaryOutput(output);
22
+ for (const { job, image, source } of extractImageRefs(yaml)) {
23
+ if (image.includes("@sha256:")) continue;
24
+ if (image.includes("$")) continue; // variable-based reference — not statically knowable
25
+ diagnostics.push({
26
+ checkId: "WGL031",
27
+ severity: "warning",
28
+ message: `Job "${job}" ${source === "service" ? "service image" : "image"} "${image}" is not pinned to a digest — reference it by @sha256:... so the image cannot change after review.`,
29
+ entity: job,
30
+ lexicon: "gitlab",
31
+ });
32
+ }
33
+ }
34
+
35
+ return diagnostics;
36
+ },
37
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * WGL032: Include/Component Source Resembling a Well-Known Project
3
+ *
4
+ * Flags an `include:project` path or `component:` source that is a near-miss
5
+ * (edit distance 1–2) of a well-known GitLab CI source but not an exact match —
6
+ * a likely typo or an impersonation of the trusted project. Advisory; backed by
7
+ * a vendored reference list.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractIncludes } from "./yaml-helpers";
12
+ import { KNOWN_INCLUDE_SOURCES, editDistance } from "../rules/data/known-include-sources";
13
+
14
+ const KNOWN = new Set(KNOWN_INCLUDE_SOURCES);
15
+
16
+ /** Reduce a component address (`host/group/name@ver`) or project path to its group/name path. */
17
+ function sourcePath(value: string, kind: string): string {
18
+ let v = value;
19
+ if (kind === "component") {
20
+ const at = v.lastIndexOf("@");
21
+ if (at !== -1) v = v.slice(0, at);
22
+ const slash = v.indexOf("/");
23
+ if (slash !== -1 && v.slice(0, slash).includes(".")) v = v.slice(slash + 1); // drop host
24
+ }
25
+ return v;
26
+ }
27
+
28
+ export function nearestKnownSource(path: string): string | undefined {
29
+ if (KNOWN.has(path)) return undefined;
30
+ let best: string | undefined;
31
+ let bestDist = 3;
32
+ for (const known of KNOWN) {
33
+ const d = editDistance(path, known, 2);
34
+ if (d >= 1 && d <= 2 && d < bestDist) {
35
+ best = known;
36
+ bestDist = d;
37
+ }
38
+ }
39
+ return best;
40
+ }
41
+
42
+ export const wgl032: PostSynthCheck = {
43
+ id: "WGL032",
44
+ description: "Include/component source resembles a well-known project (possible impersonation)",
45
+
46
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
47
+ const diagnostics: PostSynthDiagnostic[] = [];
48
+
49
+ for (const [, output] of ctx.outputs) {
50
+ const yaml = getPrimaryOutput(output);
51
+ for (const entry of extractIncludes(yaml)) {
52
+ if (entry.kind !== "project" && entry.kind !== "component") continue;
53
+ const path = sourcePath(entry.value, entry.kind);
54
+ const lookAlike = nearestKnownSource(path);
55
+ if (!lookAlike) continue;
56
+ diagnostics.push({
57
+ checkId: "WGL032",
58
+ severity: "warning",
59
+ message: `Include source "${path}" closely resembles the well-known "${lookAlike}". Confirm the source is who you intend — this may be a typo or impersonation.`,
60
+ entity: entry.value,
61
+ lexicon: "gitlab",
62
+ });
63
+ }
64
+ }
65
+
66
+ return diagnostics;
67
+ },
68
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WGL033: OIDC id_token Without a Scoped Audience
3
+ *
4
+ * Flags an `id_tokens:` declaration with no `aud:` or a wildcard audience. The
5
+ * audience binds the minted OIDC token to a specific relying party; without it
6
+ * (or with `*`), a leaked token is accepted anywhere, defeating the point of
7
+ * short-lived federated identity. Set `aud:` to the exact audience(s) needed.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractIdTokens } from "./yaml-helpers";
12
+
13
+ export const wgl033: PostSynthCheck = {
14
+ id: "WGL033",
15
+ description: "OIDC id_token without a scoped audience",
16
+
17
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
18
+ const diagnostics: PostSynthDiagnostic[] = [];
19
+
20
+ for (const [, output] of ctx.outputs) {
21
+ const yaml = getPrimaryOutput(output);
22
+ for (const { job, name, aud } of extractIdTokens(yaml)) {
23
+ const broad = aud.length === 0 || aud.some((a) => a === "*" || a === "" || a.includes("*"));
24
+ if (broad) {
25
+ diagnostics.push({
26
+ checkId: "WGL033",
27
+ severity: "warning",
28
+ message: `Job "${job}" id_token "${name}" has ${aud.length === 0 ? "no aud:" : "a wildcard audience"}. Scope it to the exact audience the relying party expects so a leaked token cannot be used elsewhere.`,
29
+ entity: job,
30
+ lexicon: "gitlab",
31
+ });
32
+ }
33
+ }
34
+ }
35
+
36
+ return diagnostics;
37
+ },
38
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * WGL034: OIDC id_token Mintable from a Merge-Request Pipeline
3
+ *
4
+ * Flags a job that declares an `id_tokens:` (OIDC) and is reachable from
5
+ * merge-request pipelines. MR pipelines can be triggered by outside
6
+ * contributors, so a job that mints a cloud-federated token there hands fork
7
+ * code a path to your cloud roles. Gate OIDC jobs to protected refs, or require
8
+ * approval before they run.
9
+ */
10
+
11
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
+ import { getPrimaryOutput, extractIdTokens, extractJobSection, isMergeRequestReachable } from "./yaml-helpers";
13
+
14
+ export const wgl034: PostSynthCheck = {
15
+ id: "WGL034",
16
+ description: "OIDC id_token mintable from a merge-request pipeline",
17
+
18
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
19
+ const diagnostics: PostSynthDiagnostic[] = [];
20
+
21
+ for (const [, output] of ctx.outputs) {
22
+ const yaml = getPrimaryOutput(output);
23
+ const seen = new Set<string>();
24
+ for (const { job } of extractIdTokens(yaml)) {
25
+ if (seen.has(job)) continue;
26
+ const section = extractJobSection(yaml, job);
27
+ if (section && isMergeRequestReachable(section)) {
28
+ seen.add(job);
29
+ diagnostics.push({
30
+ checkId: "WGL034",
31
+ severity: "warning",
32
+ message: `Job "${job}" mints an OIDC id_token and is reachable from merge-request pipelines, which outside contributors can trigger. Restrict it to protected refs or require approval before it runs.`,
33
+ entity: job,
34
+ lexicon: "gitlab",
35
+ });
36
+ }
37
+ }
38
+ }
39
+
40
+ return diagnostics;
41
+ },
42
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WGL035: Untrusted CI Variable Interpolated into a Script
3
+ *
4
+ * Flags an attacker-controllable predefined variable (branch/tag name, commit or
5
+ * merge-request title/description, author) referenced in a `script:` command. A
6
+ * crafted branch name or commit title containing shell metacharacters can break
7
+ * out of the command. Quote the reference and avoid using it in sensitive
8
+ * commands, or sanitize it first.
9
+ */
10
+
11
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
+ import { getPrimaryOutput, extractScriptCommands } from "./yaml-helpers";
13
+ import { UNTRUSTED_CI_VARIABLES, variableReferenced } from "../rules/data/untrusted-variables";
14
+
15
+ export const wgl035: PostSynthCheck = {
16
+ id: "WGL035",
17
+ description: "Untrusted CI variable interpolated into a script command",
18
+
19
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
20
+ const diagnostics: PostSynthDiagnostic[] = [];
21
+
22
+ for (const [, output] of ctx.outputs) {
23
+ const yaml = getPrimaryOutput(output);
24
+ const seen = new Set<string>();
25
+ for (const { job, command } of extractScriptCommands(yaml)) {
26
+ for (const name of UNTRUSTED_CI_VARIABLES) {
27
+ if (!variableReferenced(command, name)) continue;
28
+ const key = `${job}:${name}`;
29
+ if (seen.has(key)) continue;
30
+ seen.add(key);
31
+ diagnostics.push({
32
+ checkId: "WGL035",
33
+ severity: "warning",
34
+ message: `Job "${job}" uses the attacker-controllable variable $${name} in a script command. A crafted value can inject shell commands — quote it ("$${name}") and avoid using it in sensitive commands, or sanitize it first.`,
35
+ entity: job,
36
+ lexicon: "gitlab",
37
+ });
38
+ }
39
+ }
40
+ }
41
+
42
+ return diagnostics;
43
+ },
44
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * WGL036: Privileged Service / Docker-in-Docker Reachable from Merge Requests
3
+ *
4
+ * Flags a job that uses Docker-in-Docker (a privileged service) and is reachable
5
+ * from merge-request pipelines. MR pipelines can run code from an outside
6
+ * contributor; a privileged DinD service shares the host daemon socket and can
7
+ * be used to escape the build and reach the runner. Restrict privileged services
8
+ * to protected refs, or require approval before such jobs run.
9
+ *
10
+ * Complements WGL026 (DinD without TLS) by adding the trust-boundary dimension.
11
+ */
12
+
13
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
14
+ import { getPrimaryOutput, extractJobs, extractJobSection, isMergeRequestReachable } from "./yaml-helpers";
15
+
16
+ const DIND_RE = /docker:[\w.-]*dind|dind|privileged:\s*true/;
17
+
18
+ export const wgl036: PostSynthCheck = {
19
+ id: "WGL036",
20
+ description: "Privileged service / DinD reachable from merge-request pipelines",
21
+
22
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
23
+ const diagnostics: PostSynthDiagnostic[] = [];
24
+
25
+ for (const [, output] of ctx.outputs) {
26
+ const yaml = getPrimaryOutput(output);
27
+ for (const [job] of extractJobs(yaml)) {
28
+ const section = extractJobSection(yaml, job);
29
+ if (!section) continue;
30
+ if (DIND_RE.test(section) && isMergeRequestReachable(section)) {
31
+ diagnostics.push({
32
+ checkId: "WGL036",
33
+ severity: "warning",
34
+ message: `Job "${job}" runs a privileged Docker-in-Docker service and is reachable from merge-request pipelines, which outside contributors can trigger. Restrict privileged services to protected refs or require approval.`,
35
+ entity: job,
36
+ lexicon: "gitlab",
37
+ });
38
+ }
39
+ }
40
+ }
41
+
42
+ return diagnostics;
43
+ },
44
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * WGL037: Security Gate on a Regex Match of an Untrusted Ref
3
+ *
4
+ * Flags a `rules:if` that gates execution on a regex match (`=~`) over an
5
+ * attacker-controllable ref variable (e.g. `$CI_COMMIT_REF_NAME =~ /^release/`).
6
+ * An outside contributor can craft a branch name that satisfies the pattern
7
+ * (`release-evil`), passing a gate meant for trusted refs. Match the full ref
8
+ * with `==`, or gate on a protected condition instead.
9
+ */
10
+
11
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
12
+ import { getPrimaryOutput, extractJobs, extractJobSection } from "./yaml-helpers";
13
+ import { UNTRUSTED_CI_VARIABLES } from "../rules/data/untrusted-variables";
14
+
15
+ const REF_VARS = ["CI_COMMIT_REF_NAME", "CI_COMMIT_REF_SLUG", "CI_COMMIT_BRANCH", "CI_COMMIT_TAG", "CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"]
16
+ .filter((v) => UNTRUSTED_CI_VARIABLES.includes(v));
17
+
18
+ export const wgl037: PostSynthCheck = {
19
+ id: "WGL037",
20
+ description: "Security gate on a regex match of an untrusted ref variable",
21
+
22
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
23
+ const diagnostics: PostSynthDiagnostic[] = [];
24
+
25
+ for (const [, output] of ctx.outputs) {
26
+ const yaml = getPrimaryOutput(output);
27
+ for (const [job] of extractJobs(yaml)) {
28
+ const section = extractJobSection(yaml, job);
29
+ if (!section) continue;
30
+ // Look at `if:` lines that use a regex match against an untrusted ref var.
31
+ const ifLines = section.split("\n").filter((l) => /if:\s/.test(l));
32
+ const flagged = ifLines.some((l) => /=~/.test(l) && REF_VARS.some((v) => l.includes(`$${v}`)));
33
+ if (flagged) {
34
+ diagnostics.push({
35
+ checkId: "WGL037",
36
+ severity: "warning",
37
+ message: `Job "${job}" gates on a regex match (=~) of an attacker-controllable ref variable. A crafted branch/tag name can satisfy the pattern — match the full ref with == or gate on a protected condition.`,
38
+ entity: job,
39
+ lexicon: "gitlab",
40
+ });
41
+ }
42
+ }
43
+ }
44
+
45
+ return diagnostics;
46
+ },
47
+ };
@@ -0,0 +1,48 @@
1
+ /**
2
+ * WGL038: Secret Reachable from a Merge-Request Pipeline
3
+ *
4
+ * Flags a user-defined secret-like variable (`*_PASSWORD`, `*_SECRET`,
5
+ * `*_TOKEN`, `*_API_KEY`, …) referenced in a job reachable from merge-request
6
+ * pipelines. Those pipelines can run an outside contributor's code, so a secret
7
+ * they can read is a secret they can exfiltrate. Gate secret-using jobs to
8
+ * protected refs, or make the variable protected so MR pipelines can't see it.
9
+ *
10
+ * Built-in `CI_*` variables are project-managed and excluded.
11
+ */
12
+
13
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
14
+ import { getPrimaryOutput, extractJobs, extractJobSection, isMergeRequestReachable } from "./yaml-helpers";
15
+
16
+ const SECRET_VAR = /\$\{?((?!CI_)[A-Z][A-Z0-9_]*(?:PASSWORD|SECRET|TOKEN|API[_-]?KEY|PRIVATE[_-]?KEY|CREDENTIALS?))\}?/g;
17
+
18
+ export const wgl038: PostSynthCheck = {
19
+ id: "WGL038",
20
+ description: "Secret-like variable reachable from a merge-request pipeline",
21
+
22
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
23
+ const diagnostics: PostSynthDiagnostic[] = [];
24
+
25
+ for (const [, output] of ctx.outputs) {
26
+ const yaml = getPrimaryOutput(output);
27
+ for (const [job] of extractJobs(yaml)) {
28
+ const section = extractJobSection(yaml, job);
29
+ if (!section || !isMergeRequestReachable(section)) continue;
30
+ const found = new Set<string>();
31
+ let m: RegExpExecArray | null;
32
+ SECRET_VAR.lastIndex = 0;
33
+ while ((m = SECRET_VAR.exec(section)) !== null) found.add(m[1]);
34
+ if (found.size > 0) {
35
+ diagnostics.push({
36
+ checkId: "WGL038",
37
+ severity: "warning",
38
+ message: `Job "${job}" reads secret-like variable(s) ${[...found].map((v) => `$${v}`).join(", ")} and is reachable from merge-request pipelines, which can run untrusted code. Gate it to protected refs or mark the variable protected.`,
39
+ entity: job,
40
+ lexicon: "gitlab",
41
+ });
42
+ }
43
+ }
44
+ }
45
+
46
+ return diagnostics;
47
+ },
48
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * WGL039: Secret Echoed to Job Logs
3
+ *
4
+ * Flags a `script:` command that prints a secret-like variable (`echo`,
5
+ * `printf`, `print`, `cat`) — even masked variables leak when transformed
6
+ * (base64, reversed) before printing, and job logs are broadly readable.
7
+ * Remove the debug print or pipe the value where it is needed without echoing it.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractScriptCommands } from "./yaml-helpers";
12
+
13
+ const PRINT_SECRET = /\b(echo|printf|print|cat)\b[^\n]*\$\{?[A-Z][A-Z0-9_]*(?:PASSWORD|SECRET|TOKEN|API[_-]?KEY|PRIVATE[_-]?KEY|CREDENTIALS?)\}?/i;
14
+
15
+ export const wgl039: PostSynthCheck = {
16
+ id: "WGL039",
17
+ description: "Secret-like variable printed to job logs",
18
+
19
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
20
+ const diagnostics: PostSynthDiagnostic[] = [];
21
+
22
+ for (const [, output] of ctx.outputs) {
23
+ const yaml = getPrimaryOutput(output);
24
+ const seen = new Set<string>();
25
+ for (const { job, command } of extractScriptCommands(yaml)) {
26
+ if (PRINT_SECRET.test(command) && !seen.has(job)) {
27
+ seen.add(job);
28
+ diagnostics.push({
29
+ checkId: "WGL039",
30
+ severity: "warning",
31
+ message: `Job "${job}" prints a secret-like variable to the job log. Logs are broadly readable and masking can be defeated by transforms — remove the print.`,
32
+ entity: job,
33
+ lexicon: "gitlab",
34
+ });
35
+ }
36
+ }
37
+ }
38
+
39
+ return diagnostics;
40
+ },
41
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * WGL040: Hardcoded Credential in a Registry Login
3
+ *
4
+ * Flags a `docker login` (or compatible) in a `script:` that passes a literal
5
+ * password via `-p` / `--password` instead of a variable or `--password-stdin`.
6
+ * An inlined credential sits in the committed pipeline and the job log. Use a
7
+ * masked CI/CD variable and `--password-stdin`. Extends WGL016 to scripts.
8
+ */
9
+
10
+ import type { PostSynthCheck, PostSynthContext, PostSynthDiagnostic } from "@intentius/chant/lint/post-synth";
11
+ import { getPrimaryOutput, extractScriptCommands } from "./yaml-helpers";
12
+
13
+ // docker/podman/buildah/helm login with -p/--password followed by a non-variable literal
14
+ const LITERAL_LOGIN = /\b(?:docker|podman|buildah|helm|crane|skopeo)\b[^\n]*\blogin\b[^\n]*(?:-p|--password)[=\s]+(?!["']?\$)["']?[^\s"']+/i;
15
+
16
+ export const wgl040: PostSynthCheck = {
17
+ id: "WGL040",
18
+ description: "Hardcoded credential in a registry login command",
19
+
20
+ check(ctx: PostSynthContext): PostSynthDiagnostic[] {
21
+ const diagnostics: PostSynthDiagnostic[] = [];
22
+
23
+ for (const [, output] of ctx.outputs) {
24
+ const yaml = getPrimaryOutput(output);
25
+ const seen = new Set<string>();
26
+ for (const { job, command } of extractScriptCommands(yaml)) {
27
+ if (LITERAL_LOGIN.test(command) && !seen.has(job)) {
28
+ seen.add(job);
29
+ diagnostics.push({
30
+ checkId: "WGL040",
31
+ severity: "error",
32
+ message: `Job "${job}" passes a hardcoded password to a registry login. Use a masked CI/CD variable with --password-stdin instead of inlining the credential.`,
33
+ entity: job,
34
+ lexicon: "gitlab",
35
+ });
36
+ }
37
+ }
38
+ }
39
+
40
+ return diagnostics;
41
+ },
42
+ };