-
Notifications
You must be signed in to change notification settings - Fork 1.3k
install: warn instead of failing when checksums.txt is missing #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,17 +52,11 @@ describe("getExpectedChecksum", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("throws [SECURITY] when checksums.txt does not exist (fail-closed)", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("returns null when checksums.txt does not exist", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), "checksum-test-")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // No checksums.txt in dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.throws( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => getExpectedChecksum("anything.tar.gz", dir), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.match(err.message, /^\[SECURITY\]/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.match(err.message, /checksums\.txt not found/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = getExpectedChecksum("anything.tar.gz", dir); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(result, null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Assert the warning before accepting the fail-open result. This test now verifies the Suggested test hardening- it("returns null when checksums.txt does not exist", () => {
+ it("returns null and warns when checksums.txt does not exist", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "checksum-test-"));
// No checksums.txt in dir
- const result = getExpectedChecksum("anything.tar.gz", dir);
- assert.equal(result, null);
+ const originalError = console.error;
+ const messages = [];
+ console.error = (...args) => messages.push(args.join(" "));
+ try {
+ const result = getExpectedChecksum("anything.tar.gz", dir);
+ assert.equal(result, null);
+ assert.match(
+ messages.join("\n"),
+ /\[WARN\] checksums\.txt not found, skipping checksum verification/
+ );
+ } finally {
+ console.error = originalError;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("skips malformed lines and still finds valid entry", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -131,19 +125,6 @@ describe("verifyChecksum", () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it("verifyChecksum throws [SECURITY] on null/empty expectedHash (fail-closed)", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filePath = makeTmpFile("content"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const expectedHash of [null, ""]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.throws( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| () => verifyChecksum(filePath, expectedHash), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (err) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert.match(err.message, /^\[SECURITY\]/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe("assertAllowedHost", () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Gate unverified installs behind an explicit opt-in.
This path now installs a downloaded binary with no checksum verification whenever
checksums.txtis missing. A warning is easy to miss duringnpm install; consider failing closed by default and allowing the old behavior only via an explicit escape hatch.Suggested direction
if (!fs.existsSync(checksumsPath)) { - console.error( - "[WARN] checksums.txt not found, skipping checksum verification" - ); - return null; + const message = "checksums.txt not found"; + if (process.env.LARK_CLI_ALLOW_UNVERIFIED_INSTALL === "1") { + console.error( + `[WARN] ${message}, skipping checksum verification` + ); + return null; + } + throw new Error( + `[SECURITY] ${message}; refusing to install an unverified binary. Set LARK_CLI_ALLOW_UNVERIFIED_INSTALL=1 to proceed.` + ); }Also applies to: 289-289
🤖 Prompt for AI Agents