Skip to content

Commit

Permalink
Warn invalid NSP empty record (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnturner committed Dec 16, 2022
1 parent acabc36 commit 5b2cf71
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/nsp-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,25 @@ export function getAllowlistId(nspRecord: NSPRecord | GitHubNSPRecord): string {
export function getNSPContent(
nspRecord: NSPRecord | GitHubNSPRecord
): NSPContent {
return Object.values(nspRecord)[0];
const values = Object.values(nspRecord);
if (values.length > 0) {
return values[0];
}
throw new Error(
`Empty NSPRecord is invalid. Here's an example of a valid NSPRecord:
{
"allowlist": [
{
"vulnerable-module": {
"active": true,
"notes": "This is a note",
"expiry": "2022-01-01"
}
}
]
}
`
);
}

/**
Expand Down

0 comments on commit 5b2cf71

Please sign in to comment.