|
1
|
--- |
|
2
|
name: diagnosing-dependabot-alerts |
|
3
|
description: Diagnoses GitHub Dependabot / security alerts in the Medusa monorepo and finds the least-invasive fix. Use when investigating a Dependabot alert, security advisory (GHSA/CVE), vulnerable dependency, "npm audit" finding, or a security update PR. Traces the vulnerable package to the exact affected workspace package(s) under packages/, assesses real impact, and prefers a fix scoped to the affected package over a root package.json / yarn.lock resolutions override (which is a last resort). |
|
4
|
--- |
|
5
|
|
|
6
|
# Diagnosing Dependabot Alerts |
|
7
|
|
|
8
|
Investigate a Dependabot/security alert in the Medusa monorepo, identify the exact affected package(s), assess real-world impact, and pick the least-invasive fix. Default output is a diagnosis; only make changes when asked. |
|
9
|
|
|
10
|
## Constraints |
|
11
|
|
|
12
|
- **Diagnose first, don't default to a fix:** Never jump to a root `resolutions`/`overrides` bump. Root-level overrides are the LAST resort — see the remediation ladder. |
|
13
|
- **Root overrides don't ship:** `resolutions` (yarn) / `overrides` (npm) apply only to THIS repo's install. They are NOT published with `packages/*`, so they do not protect downstream consumers of a published package. Never present them as a full fix for a vulnerability that reaches a published package. |
|
14
|
- **Find the fix inside the affected package first:** Prefer refreshing/bumping the dependency within the workspace package that owns it (transitive refresh or direct-dep bump) before touching anything at the monorepo root. |
|
15
|
- **Reachable is not pinnable:** A fixed version being resolvable within existing semver ranges (a lockfile float) is weaker than a range that GUARANTEES the fix. Call out the difference — the float can regress for downstream consumers. |
|
16
|
- **Assess impact, don't assume:** Determine whether the vulnerable code path is actually reachable with untrusted input in Medusa before recommending urgency. |
|
17
|
|
|
18
|
## Workflow |
|
19
|
|
|
20
|
Follow these steps in order. Load `reference/remediation-strategies.md` before proposing any fix. |
|
21
|
|
|
22
|
``` |
|
23
|
1. Fetch alert details → gh api (package, versions, scope) |
|
24
|
2. Trace to affected package → walk yarn.lock up to packages/* |
|
25
|
3. Assess real impact → is the vulnerable path reachable? |
|
26
|
4. Choose remediation → remediation ladder (least-invasive first) |
|
27
|
5. Verify (only if changing) → scoped diff, no vulnerable version remains |
|
28
|
``` |
|
29
|
|
|
30
|
### 1. Fetch alert details |
|
31
|
|
|
32
|
The alert number is the last path segment of the URL (`.../dependabot/<N>`). |
|
33
|
|
|
34
|
```bash |
|
35
|
gh api repos/medusajs/medusa/dependabot/alerts/<N> | jq '{ |
|
36
|
state, package: .dependency.package.name, scope: .dependency.scope, |
|
37
|
relationship: .dependency.relationship, manifest: .dependency.manifest_path, |
|
38
|
ghsa: .security_advisory.ghsa_id, severity: .security_advisory.severity, |
|
39
|
summary: .security_advisory.summary, |
|
40
|
matched_range: .security_vulnerability.vulnerable_version_range, |
|
41
|
first_patched: .security_vulnerability.first_patched_version.identifier, |
|
42
|
all_ranges: [.security_advisory.vulnerabilities[] | {range: .vulnerable_version_range, patched: .first_patched_version.identifier}] |
|
43
|
}' |
|
44
|
``` |
|
45
|
|
|
46
|
Record: the vulnerable package name, every `{vulnerable range → first patched}` pair, and whether the alert is `direct` or `transitive`. |
|
47
|
|
|
48
|
### 2. Trace to the exact affected Medusa package(s) |
|
49
|
|
|
50
|
Find which version(s) are actually installed and walk up the dependency chain to the workspace package(s) under `packages/` that own the dependency. See `reference/remediation-strategies.md` for the full tracing recipe. In short: |
|
51
|
|
|
52
|
1. `grep -n "<pkg>@npm" yarn.lock` — list installed versions; confirm which match the vulnerable range. |
|
53
|
2. Walk up dependents (grep the version string as a dependency of other lock entries) until you reach a package declared in a `packages/*/package.json`. |
|
54
|
3. For that workspace package, determine: |
|
55
|
- **Direct vs transitive** — is `<pkg>` (or the nearest ancestor) in its `dependencies`/`devDependencies`, or purely transitive? |
|
56
|
- **Ships or not** — `private: false` means it publishes; a runtime `dependencies` entry ships to consumers. `devDependencies` and `private: true` do not. |
|
57
|
- **Runtime-reachable** — is the ancestor actually imported in `src/` (runtime), or only used at build/test time? |
|
58
|
|
|
59
|
The "affected package" is the workspace package whose manifest declares the dependency (or the nearest ancestor that does). |
|
60
|
|
|
61
|
### 3. Assess real impact |
|
62
|
|
|
63
|
Before recommending urgency, check whether the vulnerable code path is reachable with untrusted input in Medusa. Example from a past alert: `immutable` prototype pollution reached us only through `@graphql-codegen/typescript`, used to generate types from Medusa's OWN internal GraphQL schema — no untrusted input, so practical exploitability was negligible. State the impact explicitly; it changes how aggressive the fix needs to be. |
|
64
|
|
|
65
|
### 4. Choose remediation (least-invasive first) |
|
66
|
|
|
67
|
**Load `reference/remediation-strategies.md` now.** Apply the ladder in order and stop at the first tier that works without breaking changes: |
|
68
|
|
|
69
|
| Tier | Fix | Scope | Ships to consumers? | |
|
70
|
|------|-----|-------|---------------------| |
|
71
|
| 1a | In-range transitive refresh (lockfile only) | affected pkg's tree | reflects fresh installs | |
|
72
|
| 1b | Bump the direct dep the affected pkg declares | affected pkg's `package.json` | yes (enforced) | |
|
73
|
| 2 | Root `resolutions`/`overrides` | this repo only | **NO** — last resort | |
|
74
|
|
|
75
|
- Prefer **1a** when a fixed version is reachable within existing ranges and introduces no breaking changes (fastest, no manifest change). |
|
76
|
- Use **1b** when the fix is only *guaranteed* by bumping the declared dep — check breaking changes (major bump, peerDeps, changed API usage) per the reference file. |
|
77
|
- Use **2** only when no in-package option exists; always state that it does not protect downstream consumers of published packages. |
|
78
|
|
|
79
|
### 5. Verify (only when making changes) |
|
80
|
|
|
81
|
- `git diff --stat` — confirm the change is scoped (only `yarn.lock`, plus `package.json` if you bumped a direct dep). |
|
82
|
- Confirm NO version matching the vulnerable range remains in `yarn.lock`. |
|
83
|
- Confirm the diff touches only the vulnerable package's dependency neighborhood — no unrelated churn. |
|
84
|
- If a direct dep was bumped: build/typecheck the affected package and exercise its use of the dependency. |
|
85
|
|
|
86
|
## Reference Files Available |
|
87
|
|
|
88
|
``` |
|
89
|
reference/remediation-strategies.md - Tracing recipe, semver reachable-vs-pinnable |
|
90
|
analysis, per-tier commands, breaking-change checks |
|
91
|
``` |
|
92
|
|
|
93
|
## Common Mistakes Checklist |
|
94
|
|
|
95
|
Verify you're NOT doing these: |
|
96
|
|
|
97
|
- [ ] Adding a root `resolutions`/`overrides` entry as the first (or only) fix |
|
98
|
- [ ] Presenting a root override as protecting downstream consumers of a published package |
|
99
|
- [ ] Treating a lockfile float ("reachable") as a guaranteed fix ("pinnable") |
|
100
|
- [ ] Skipping the trace and not naming the exact affected `packages/*` package(s) |
|
101
|
- [ ] Recommending a major-version bump without checking breaking changes / peerDeps / actual usage |
|
102
|
- [ ] Reporting urgency without checking whether the vulnerable path is reachable in Medusa |
|
103
|
- [ ] Making changes when only a diagnosis was requested |