Skip to content

Fix CLI scan completion, error handling, and advisory deduplication - #623

Merged
eoftedal merged 3 commits into
RetireJS:masterfrom
PekSec:codex/cli-correctness
Oct 6, 2026
Merged

eoftedal merged 3 commits into
RetireJS:masterfrom
PekSec:codex/cli-correctness

Conversation

@PekSec

@PekSec PekSec commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

CLI scans could close reports before asynchronous OSV findings arrived, and malformed inputs or repository responses could escape the intended error path. This PR waits for scan completion before finalizing output, validates terminal CLI input, handles malformed local/remote JSON with source context, and passes the insecure option through repository loading.

It also fixes the exclusive upper license boundary and platform-dependent Bower path handling, and preserves distinct CVEs sharing an issue while removing repeated advisories.

This is the CLI-only replacement for the relevant part of #622, as requested. It changes seven CLI/core/test files; extension rewrites, portable build scripts, and CycloneDX changes are excluded.

Validation: 70 tests pass, TypeScript checking and nonfixing ESLint pass, repository validation passes, and the full detection suite completes successfully across 48 packages. On Windows, the unchanged Unix-oriented npm scripts were run using equivalent direct Node/TypeScript commands against freshly compiled output.

AI-assisted implementation, with regression tests for the corrected behavior.

Related independent replacements: browser extensions #624 and CycloneDX #625.

@eoftedal

Copy link
Copy Markdown
Member

Why the full rewrite from eventemitter to async?
That makes this change very hard to review and makes in a serious architectural change.

@eoftedal

Copy link
Copy Markdown
Member

Tests should be split into test files per module. Example: license tests

@eoftedal

Copy link
Copy Markdown
Member

getIdentifiers has changed semantics. Why?

@eoftedal

Copy link
Copy Markdown
Member

Commits must have verified signatures.

@PekSec
PekSec force-pushed the codex/cli-correctness branch from 018599e to 703593f Compare September 24, 2026 10:36
@PekSec

PekSec commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

The change addresses a completion-order bug introduced with OSV integration: directory traversal can finish while OSV requests are still pending. In an isolated reproduction using the old and new sources, the old CLI closed the report with no findings and exit code 0; the new code waited and closed with the finding and exit code 13. Scanner events remain intact. The waiting is necessary, although moving the entire CLI into async main() is not required to fix it.

@PekSec

PekSec commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Previously, any shared identifier could collapse two advisories, including a shared issue number. Bootstrap issue 20184 covers multiple distinct CVEs, so this dropped valid findings. The change prioritizes CVE/GHSA identifiers and namespaces fallback identifiers. The tradeoff is that an issue-only record may remain separate from a CVE-bearing record for the same vulnerability.

@PekSec

PekSec commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

The tests are now split by module into CLI, scanner, repository, depsdev, and license specs. All 70 tests pass, along with the build, TypeScript checks, and ESLint. The updated commit, 703593f, has a verified SSH signature. Production code is unchanged from the previous PR revision.

@eoftedal eoftedal closed this in #625 Oct 2, 2026
@eoftedal eoftedal reopened this Oct 2, 2026
@eoftedal

eoftedal commented Oct 2, 2026

Copy link
Copy Markdown
Member

Hmm. why was this closed by the other merge. Not intentional

@eoftedal

eoftedal commented Oct 2, 2026

Copy link
Copy Markdown
Member

The change addresses a completion-order bug introduced with OSV integration: directory traversal can finish while OSV requests are still pending. In an isolated reproduction using the old and new sources, the old CLI closed the report with no findings and exit code 0; the new code waited and closed with the finding and exit code 13. Scanner events remain intact. The waiting is necessary, although moving the entire CLI into async main() is not required to fix it.

Can we reduce the size of the new main? The commandline argument parsing etc. is using sync methods because it all needs to be done before we can continue, so it's deliberately not async or using callbacks.

@PekSec

PekSec commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Removed the async main wrapper; setup stays synchronous while scans still await OSV results.

@eoftedal

eoftedal commented Oct 4, 2026

Copy link
Copy Markdown
Member

Removed the async main wrapper; setup stays synchronous while scans still await OSV results.

Thanks. Does the try catch really need to cover the entire cli.ts? It makes this PR so hard to review.

Comment thread node/src/cli.ts Resolved
Comment thread node/src/cli.ts Outdated
);
}
const severity = prg.severity ?? 'none';
if (!Object.prototype.hasOwnProperty.call(severityLevels, severity)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A lot less readable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Show probably rewrite this to us a zod schema

Comment thread node/src/scanner.ts Outdated
if (bower.version) {
const results = retire.check(bower.name, bower.version, repo);
emitResults({ file: file, results: results }, options, repo);
return emitResults({ file: file, results: results }, options, repo);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this be awaited now that emitResults is async ?

Comment thread node/src/scanner.ts Outdated
}
}
emitResults({ file: file, results: results }, options, repo);
return emitResults({ file: file, results: results }, options, repo);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this be awaited now that emitResults is async?

Comment thread node/spec/tests/scanner.spec.ts Outdated
import { run } from '../run-script';

it('preserves distinct Bootstrap CVEs sharing an issue while removing repeated advisories', () => {
run(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we solve this without the massive evals? (run-script)

Comment thread node/spec/tests/scanner.spec.ts Outdated
});

it('keeps fallback identifier namespaces separate and prefers canonical identifiers', () => {
run(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we solve this without the massive evals? (run-script)

Comment thread node/spec/tests/scanner.spec.ts Outdated
});

it('awaits OSV results before resolving file scans', () => {
run(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we solve this without the massive evals? (run-script)

Comment thread node/spec/tests/repo.spec.ts Outdated
import { it } from 'node:test';
import { run } from '../run-script';

it('rejects malformed local and remote repositories with source context', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we solve this without the massive evals? (run-script)

Comment thread node/spec/tests/depsdev.spec.ts Outdated
import { run } from '../run-script';

it('handles malformed OSV JSON through the warning path', () => {
run(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we solve this without the massive evals? (run-script)

@PekSec

PekSec commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Narrowed the try/catch, added explicit awaits, removed the eval blocks, and switched severity validation to Zod.

@PekSec
PekSec requested a review from eoftedal October 6, 2026 06:09
@eoftedal
eoftedal merged commit a9c46ea into RetireJS:master Oct 6, 2026
3 checks passed
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