Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,8 @@ The full scan artifact in JSON format. Contains all raw data, scores, findings,

[Static Analysis Results Interchange Format](https://sarifweb.azurewebsites.net/) — compatible with GitHub Code Scanning and Azure DevOps. Contains findings only (not all metrics). Ideal for integrating drift findings directly into your PR review workflow.

A declared license names its evidence file in JSON and SARIF when `vg scan` has one. A `package.json` `license` or `licenses` field is that file; otherwise the first existing `LICENSE`, `LICENCE`, `COPYING`, or `NOTICE` file in the project directory (also `.md` and `.txt`, in that order) is. The path is `projects[].license.path`. Text that does not resolve as SPDX is a `vibgrate/license-parse-failed` finding: JSON sets `location` and `details.path` to the repo-relative path, and SARIF uses the same path as `physicalLocation.artifactLocation.uri` and `properties.path`. The license body is not copied into the artifact. An explicit `NOASSERTION` is not a failure. A registry license string has no local file, so the finding stays on the dependency and `location` remains the project path, without `details.path`. Those file findings are sorted by path.

Test reporters that ingest JUnit can take a companion file from the same scan. See [JUnit](#junit). The process exit code is unchanged either way; see [Exit Codes](#exit-codes).

### Markdown
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ One scan gives you:
- **Score breakdown** — runtime, frameworks, dependencies, EOL
- **Per-project detail** across Node.js/TypeScript, .NET, Python, and Java
- **Actionable findings** ranked by likely impact
- **License evidence paths** in JSON and SARIF (`projects[].license.path`, finding `location`). A manifest `license` field, or a LICENSE / NOTICE / COPYING file, is named when one exists. Text that does not parse as SPDX is a `vibgrate/license-parse-failed` finding at that path; the file body is not copied into the result
- **[SBOM](https://vibgrate.com/glossary/sbom) export** (CycloneDX / SPDX)
- **Known vulnerabilities** (opt in with `--vulns`) — severity, CVSS, the fixing version, and, in a git repo, who introduced them

Expand Down
25 changes: 24 additions & 1 deletion src/core-open/licenses/dependency-license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,46 @@
* The scanner records the raw declared string plus a best-effort canonical
* SPDX id; full classification (category / obligations / risk) and the growing
* library lookup happen during API enrichment.
*
* A registry signal has no local file, so `path` stays omitted. Pass
* `evidencePath` when the declaration was read from a manifest or license
* file — scan JSON and SARIF then point the finding at that file instead of
* dropping the path.
*/
import type { DependencyLicense } from '../types.js';
import { normalizeLicense } from './normalize.js';

/**
* Repo-relative evidence path, or undefined when the caller has none.
* Rejects absolute paths and `..` so a finding never points outside the repo.
* Deterministic: only string rewriting, no filesystem access.
*/
export function licenseEvidencePath(input: string | null | undefined): string | undefined {
if (typeof input !== 'string') return undefined;
const norm = input.replace(/\\/g, '/').replace(/^\.\//, '').replace(/\/+$/, '');
if (!norm || norm === '.') return undefined;
if (norm.startsWith('/') || /^[A-Za-z]:\//.test(norm)) return undefined;
const parts = norm.split('/');
if (parts.some((segment) => segment === '' || segment === '.' || segment === '..')) return undefined;
return norm;
}

export function buildDependencyLicense(
raw: string | null | undefined,
source: DependencyLicense['source'],
evidencePath?: string | null,
): DependencyLicense {
const path = licenseEvidencePath(evidencePath);
const trimmed = (raw ?? '').trim();
if (!trimmed) {
return { raw: null, spdxId: null, source: 'none', confidence: 0 };
return { raw: null, spdxId: null, source: 'none', confidence: 0, ...(path ? { path } : {}) };
}
const verdict = normalizeLicense(trimmed);
return {
raw: trimmed.slice(0, 200),
spdxId: verdict.matchStatus === 'unknown' ? null : verdict.spdxId,
source,
confidence: verdict.confidence,
...(path ? { path } : {}),
};
}
Loading
Loading