Skip to content

feat: add yarn-within-range lockfile fixture (#5)#537

Open
coder-Yash886 wants to merge 4 commits into
OWASP:mainfrom
coder-Yash886:fixture/yarn-within-range
Open

feat: add yarn-within-range lockfile fixture (#5)#537
coder-Yash886 wants to merge 4 commits into
OWASP:mainfrom
coder-Yash886:fixture/yarn-within-range

Conversation

@coder-Yash886

@coder-Yash886 coder-Yash886 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Closes #528 (fixture #5)

Fixture: yarn-within-range

What this tests

Yarn equivalent of the wrong-parent scenario — when the immediate parent's
version range already covers the patched version, the scanner should emit
yarn upgrade <pkg> rather than bumping the parent.

Fixture structure

examples/yarn-within-range/
├── package.json
└── yarn.lock

Vulnerable package : js-cookie@3.0.6
Fix available at : 3.0.7
Parent range : ^3.0.5 (covers the fix — no parent bump needed)

Scan output

node dist/index.js examples/yarn-within-range --verbose

Parsed 3 packages from yarn-lock (yarn.lock)

✗ Found 1 package (1 CVE) with known OSV matches from yarn-lock

┌──────────┬──────┬────────┬─────┬─────────┐
│ Critical │ High │ Medium │ Low │ Unknown │
├──────────┼──────┼────────┼─────┼─────────┤
│ 0 │ 1 │ 0 │ 0 │ 0 │
└──────────┴──────┴────────┴─────┴─────────┘

Quick take

  • 0 vulnerable packages look directly fixable in this project.
  • 1 issue come through other dependencies.
  • 1 CVE matched overall.
  • 1 package include a fixed-version hint from OSV.

🛠 Fix Commands
Detected package manager: yarn (yarn.lock)

High severity parent updates within range
┌───────────┬─────────┬────────────────────┬───────┬──────────────────────────────────┐
│ Package │ Current │ Recommended target │ Usage │ Context │
├───────────┼─────────┼────────────────────┼───────┼──────────────────────────────────┤
│ js-cookie │ 3.0.6 │ lockfile refresh │ n/a │ js-cookie@3.0.6 can be refreshed │
│ │ │ │ │ to 3.0.8+ — no parent upgrade │
│ │ │ │ │ needed. │
└───────────┴─────────┴────────────────────┴───────┴──────────────────────────────────┘

yarn upgrade js-cookie

┌───────────┬─────────┬──────────┬────────────┬───────┬───────┬─────────────────────┐
│ Package │ Version │ Severity │ Type │ Usage │ Fixed │ IDs │
├───────────┼─────────┼──────────┼────────────┼───────┼───────┼─────────────────────┤
│ js-cookie │ 3.0.6 │ high │ transitive │ n/a │ 3.0.7 │
└───────────┴─────────┴──────────┴────────────┴───────┴───────┴─────────────────────┘

Verification

  • ✅ Scanner correctly detects js-cookie@3.0.6 as vulnerable
  • ✅ Emits yarn upgrade js-cookie — not a parent bump
  • ✅ Category shown as "parent updates within range" — correct path fired
  • ✅ "no parent upgrade needed" confirmed in context column
  • ✅ Package manager auto-detected as yarn (yarn.lock)

@coder-Yash886

coder-Yash886 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@sonukapoor please review the PR when you have free time

while working on this fixture I also made some improvements
to the yarn-lock parser (src/parsers/yarn-lock.ts) and added related tests.
Should I include these changes in this PR or open a separate one?

@sonukapoor sonukapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixture itself is exactly right — same aws-amplify → @aws-amplify/core → js-cookie chain as wrong-parent, Yarn edition. Scan output confirms yarn upgrade js-cookie fires correctly, no wrong parent bump. Five green verification points — well done.

One issue before this can merge: the PR includes changes from your --create-pr branch (src/cli/args.ts, src/index.ts, src/utils/create-pr.ts, related tests) which belong to PR #518 and still has open change requests. This branch was cut from your feature branch rather than main.

Please rebase against main to isolate the fixture — the examples/yarn-within-range/ files and the examples/readme.md update are all that should be here. Once rebased, this is ready to merge.

@coder-Yash886 coder-Yash886 force-pushed the fixture/yarn-within-range branch 2 times, most recently from 754d5c9 to 0bf7323 Compare June 3, 2026 13:25
@coder-Yash886

Copy link
Copy Markdown
Contributor Author

@sonukapoor please review the PR when you have free time

@sonukapoor

Copy link
Copy Markdown
Collaborator

The fixture itself is correctly constructed — the dependency chain (aws-amplify → @aws-amplify/core → js-cookie@3.0.6) is right and the vulnerability is real. However the scanner currently produces no fix command for this fixture because the Yarn Classic parser outputs flat paths (["project", "js-cookie"]) rather than reconstructing the transitive chain (["project", "aws-amplify", "@aws-amplify/core", "js-cookie"]). Without the correct path, the within-range resolver can't find @aws-amplify/core's ^3.0.5 range to suggest yarn upgrade js-cookie.

This is tracked as issue #421 — improving Yarn parser path reconstruction. The createNpmLockGraphFromYarnLock implementation you added in PR #518 is actually the fix for #421. Would you be willing to extract that work from #518 into its own PR against #421? Once that lands, this fixture will work correctly and can merge.

@coder-Yash886

Copy link
Copy Markdown
Contributor Author

@sonukapoor please review the PR when you have free time

@sonukapoor

Copy link
Copy Markdown
Collaborator

Thanks for the fixture @coder-Yash886 - the lockfile and dependency chain are correctly constructed.

I tested this against the current build and the scanner shows js-cookie@3.0.6 with a (skipped) indicator rather than generating yarn upgrade js-cookie. This is because the Yarn Classic parser currently outputs flat paths (["project", "js-cookie"]) rather than the full transitive chain (["project", "aws-amplify", "@aws-amplify/core", "js-cookie"]). Without the correct path, the within-range resolver can't identify that @aws-amplify/core's ^3.0.5 range already covers the fix.

This is tracked in issue #421. Would you be interested in opening a PR for #421 to fix the Yarn parser path reconstruction? Once that lands, this fixture will produce the correct yarn upgrade js-cookie output and can merge. The pnpm fix in #335 is a good reference for the approach.

@sonukapoor

Copy link
Copy Markdown
Collaborator

PR #576 (Yarn path reconstruction fix for #421) has just merged into main. Could you rebase this branch against main? Once rebased, examples/yarn-within-range should produce yarn upgrade js-cookie as expected and this is ready to merge.

@coder-Yash886 coder-Yash886 force-pushed the fixture/yarn-within-range branch from 57da84d to a64ab9b Compare June 8, 2026 13:23
@coder-Yash886

Copy link
Copy Markdown
Contributor Author

@sonukapoor Please review the PR

@sonukapoor

Copy link
Copy Markdown
Collaborator

Please join our slack channel https://owasp.slack.com/archives/C0B0T4BH2MR/p1780661811942929

@coder-Yash886

coder-Yash886 commented Jun 9, 2026 via email

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants