fix: SECURITY: SOPS decryption without integrity verification (#61) #70
No reviewers
Labels
No labels
action
backlog
blocked
in-progress
priority
tech-debt
underspecified
vision
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: johba/disinto#70
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/issue-61"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #61
Changes
AI Review
Security Fix: SOPS Integrity Verification
The intent is correct — adding a pre-decryption integrity check addresses #61 properly. Error handling and temp file cleanup are also improved over the original. However, there is one critical syntax bug.
Critical
critical
lib/env.sh:35:sops --verifyis not a valid SOPS flag. The correct subcommand syntax issops verify "$file"(no double-dash). Runningsops --verify file.encwill cause SOPS to exit non-zero (unknown flag), so theif !branch always triggers, printing the error and callingexit 1. Any system where.env.encexists will fail to load secrets entirely — breaking all agents. CI does not exercise this path (shellcheck only; no sops binary in CI), so the bug would not be caught until runtime.Fix: replace
sops --verify "$FACTORY_ROOT/.env.enc"withsops verify "$FACTORY_ROOT/.env.enc".Note:
sops verifywas introduced in SOPS v3.9.0. If an older SOPS version is in use that does not have theverifysubcommand at all, a different approach is needed (e.g. decrypt to /dev/null with--output-type dotenvto let SOPS validate its own MAC during decryption).Minor
lib/env.sh:51: If the secondmktemp(for_validated_env) fails,$_tmpenvleaks. In practiceset -euo pipefailstops execution, so this is not exploitable — just a nit.Verdict
REQUEST_CHANGES — sops --verify is not valid SOPS syntax; should be 'sops verify' — would break .env.enc loading on all agents
Reviewed at
4f83588| AGENTS.mdAI Review: REQUEST_CHANGES — sops --verify is not valid SOPS syntax; should be 'sops verify' — would break .env.enc loading on all agents
4f83588a4ato3a50badb01AI Re-review (round 2)
Summary
This PR adds a
sops --verifypre-check before decryption, escalates warnings to errors withexit 1, and cleans up temp files on all error paths. The error handling improvements are well-structured. However, there is a critical correctness concern with the new verify step.Findings
critical
lib/env.sh:35:sops --verifyis not a documented standard SOPS subcommand. SOPS (using age, PGP, or KMS) already verifies its MAC/GCM authentication tag implicitly duringsops -ddecryption — there is no separate--verifyflag in the standard SOPS CLI. Ifsops --verify "$FACTORY_ROOT/.env.enc"exits non-zero (which it will if the flag is unrecognized), theif !guard fires unconditionally, printingError: SOPS verification failedand callingexit 1for every script that sourcesenv.shwhen.env.encexists. This is a complete regression: the env loading block becomes permanently broken in production. CI likely passed because no.env.encis present in CI, so the outerif [ -f "$FACTORY_ROOT/.env.enc" ]guard prevents the block from running.The correct approach is to rely on the MAC verification already performed by
sops -ditself — decryption failure due to a tampered file will be caught by the existingif ! sops -d ...block. If an explicit pre-check is desired, usesops filestatus(available in SOPS v3.9+) or simply trustsops -dto reject files with invalid authentication tags.Positives
exit 1is correct defensive behavior: a tampered or unreadable secrets file should halt execution, not silently continue.rm -f "$_tmpenv") is correct.Verdict
REQUEST_CHANGES — sops --verify is not a standard SOPS command — if unrecognized, the verify gate always fails and breaks all env loading
Reviewed at
3a50bad| Previous:4f83588| AGENTS.mdAI Re-review (round 2): REQUEST_CHANGES — sops --verify is not a standard SOPS command — if unrecognized, the verify gate always fails and breaks all env loading
AI Review
Summary
This PR adds a
sops --verifypre-check before decryption, escalates warnings to errors withexit 1, and cleans up temp files on all error paths. The error handling improvements are well-structured. However, there is a critical correctness concern with the new verify step.Findings
critical
lib/env.sh:35:sops --verifyis not a documented standard SOPS subcommand. SOPS (using age, PGP, or KMS) already verifies its MAC/GCM authentication tag implicitly duringsops -ddecryption — there is no separate--verifyflag in the standard SOPS CLI. Ifsops --verify "$FACTORY_ROOT/.env.enc"exits non-zero (which it will if the flag is unrecognized), theif !guard fires unconditionally, printingError: SOPS verification failedand callingexit 1for every script that sourcesenv.shwhen.env.encexists. This is a complete regression: the env loading block becomes permanently broken in production. CI likely passed because no.env.encis present in CI, so the outerif [ -f "$FACTORY_ROOT/.env.enc" ]guard prevents the block from running.The correct approach is to rely on the MAC verification already performed by
sops -ditself — decryption failure due to a tampered file will be caught by the existingif ! sops -d ...block. If an explicit pre-check is desired, usesops filestatus(available in SOPS v3.9+) or simply trustsops -dto reject files with invalid authentication tags.Positives
exit 1is correct defensive behavior: a tampered or unreadable secrets file should halt execution, not silently continue.rm -f "$_tmpenv") is correct.Verdict
REQUEST_CHANGES — sops --verify is not a standard SOPS command — if unrecognized, the verify gate always fails and breaks all env loading
Reviewed at
4f83588| AGENTS.mdAI Review: REQUEST_CHANGES — sops --verify is not a standard SOPS command — if unrecognized, the verify gate always fails and breaks all env loading
3a50badb01to39ab881b11AI Re-review (round 4)
Previous Findings
lib/env.sh:35—sops --verifynot a valid SOPS command, always fails and breaks env loading → FIXED: The invalidsops --verifypre-check is removed. A comment now correctly documents thatsops -dalready verifies the MAC/GCM authentication tag during decryption. The fix is precise and matches the recommendation.Summary
The re-submission correctly drops the
sops --verifyregression and keeps all the good parts of the original change: escalating warnings to errors withexit 1, temp file cleanup on all error paths, and explicit failure on format validation. The comment on line 33 accurately explains the security property being relied upon.No new issues introduced.
Verdict
APPROVE — sops --verify regression removed; sops -d MAC/GCM verification is the correct mechanism
Reviewed at
39ab881| Previous:4f83588| AGENTS.mdAI Re-review (round 4): APPROVE — sops --verify regression removed; sops -d MAC/GCM verification is the correct mechanism