Arguments are checked only after the mnemonic has been read #79

Open
opened 2026-10-13 00:50:54 +02:00 by clawbot · 0 comments
Collaborator

A key index above the largest, a --words the tool does not offer, a --to that is not a recipient, and an input file that cannot be opened are all reported only after the mnemonic has been obtained: after the user has typed it at the prompt, or after the mnemonic command has run, which for secret, a password manager or a hardware token means a passphrase prompt or a touch for nothing.

Where: internal/cli/age/age.go:380-397 (derived reads the mnemonic, then derive.Bytes checks the index); internal/cli/age/age.go:111-130 with internal/agekey/agekey.go:135-148 (--to is parsed inside the work, after the mnemonic and after the input file is opened); internal/cli/mnemonic/mnemonic.go:43-65 (--words is checked by childmnemonic.Derive, after the mnemonic).

How to see: on a terminal with no mnemonic source,

./keyfunc mnemonic --words 13

prompts mnemonic: first and says a child mnemonic has 12, 18 or 24 words, not 13 only after the mnemonic is typed. Likewise ./keyfunc age pub -n 2147483648 and ./keyfunc age encrypt --to bogus file.

Definition of done: every argument check (index at most 2147483647, --words, --to recipients parse, input file opens) runs before the mnemonic is looked for. Tests in internal/cli/cli_test.go and internal/cli/age_test.go set KEYFUNC_MNEMONIC_COMMAND to a command that fails loudly and check that the argument error, not the command's failure, is what comes back.

Severity: minor. No wrong key and nothing lost; the user gives up their secret, or triggers their secret manager, for a run that cannot succeed.

Model: fable-5-1

A key index above the largest, a `--words` the tool does not offer, a `--to` that is not a recipient, and an input file that cannot be opened are all reported only after the mnemonic has been obtained: after the user has typed it at the prompt, or after the mnemonic command has run, which for `secret`, a password manager or a hardware token means a passphrase prompt or a touch for nothing. Where: `internal/cli/age/age.go:380-397` (`derived` reads the mnemonic, then `derive.Bytes` checks the index); `internal/cli/age/age.go:111-130` with `internal/agekey/agekey.go:135-148` (`--to` is parsed inside the work, after the mnemonic and after the input file is opened); `internal/cli/mnemonic/mnemonic.go:43-65` (`--words` is checked by `childmnemonic.Derive`, after the mnemonic). How to see: on a terminal with no mnemonic source, ./keyfunc mnemonic --words 13 prompts `mnemonic:` first and says `a child mnemonic has 12, 18 or 24 words, not 13` only after the mnemonic is typed. Likewise `./keyfunc age pub -n 2147483648` and `./keyfunc age encrypt --to bogus file`. **Definition of done**: every argument check (index at most 2147483647, `--words`, `--to` recipients parse, input file opens) runs before the mnemonic is looked for. Tests in `internal/cli/cli_test.go` and `internal/cli/age_test.go` set `KEYFUNC_MNEMONIC_COMMAND` to a command that fails loudly and check that the argument error, not the command's failure, is what comes back. Severity: minor. No wrong key and nothing lost; the user gives up their secret, or triggers their secret manager, for a run that cannot succeed. Model: fable-5-1
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/keyfunc#79