--index reads a leading zero as octal: -n 010 derives key 8 #75

Closed
opened 2026-10-13 00:50:51 +02:00 by clawbot · 2 comments
Collaborator

--index / -n (and --words) are read with Go's base-0 number rules, so -n 010 is index 8, -n 0x10 is index 16 and -n 1_0 is index 10. The README says only that n is the key index and nothing warns about leading zeros. A user who writes the index as 010 gets the key the README's path formula gives index 8, and anyone deriving "index 10" from the same mnemonic gets another key.

Where: internal/cli/options/options.go:19 and internal/cli/mnemonic/mnemonic.go:34 define the flags as Uint32; the flag library parses them with strconv.ParseUint(s, 0, 32).

How to see:

export KEYFUNC_MNEMONIC='abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
./keyfunc age pub -n 010
./keyfunc age pub -n 8
./keyfunc ssh pub -n 010

The first two lines are the same recipient; the third carries the comment keyfunc/ssh/8.

Definition of done: an index or word count is read as decimal digits only: 010 means 10 (or is refused), and 0x10 and 1_0 are refused with a message naming the flag. A test in internal/cli/cli_test.go runs ssh pub -n 010 and expects the index-10 line (or the refusal) and -n 0x10 refused; the same for mnemonic --words 012.

Severity: major. The tool silently derives a key at an index other than the one the user typed, though only when the index is written with a leading zero or a base prefix.

Model: fable-5-1

`--index` / `-n` (and `--words`) are read with Go's base-0 number rules, so `-n 010` is index 8, `-n 0x10` is index 16 and `-n 1_0` is index 10. The README says only that `n` is the key index and nothing warns about leading zeros. A user who writes the index as `010` gets the key the README's path formula gives index 8, and anyone deriving "index 10" from the same mnemonic gets another key. Where: `internal/cli/options/options.go:19` and `internal/cli/mnemonic/mnemonic.go:34` define the flags as `Uint32`; the flag library parses them with `strconv.ParseUint(s, 0, 32)`. How to see: export KEYFUNC_MNEMONIC='abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' ./keyfunc age pub -n 010 ./keyfunc age pub -n 8 ./keyfunc ssh pub -n 010 The first two lines are the same recipient; the third carries the comment `keyfunc/ssh/8`. **Definition of done**: an index or word count is read as decimal digits only: `010` means 10 (or is refused), and `0x10` and `1_0` are refused with a message naming the flag. A test in `internal/cli/cli_test.go` runs `ssh pub -n 010` and expects the index-10 line (or the refusal) and `-n 0x10` refused; the same for `mnemonic --words 012`. Severity: major. The tool silently derives a key at an index other than the one the user typed, though only when the index is written with a leading zero or a base prefix. Model: fable-5-1
Author
Collaborator

Severity raised to critical: the tool quietly derives a key other than the one the user asked for, which is the failure this tool exists to rule out, and the way an index is read becomes fixed once 1.0 is out.

Decided from the definition of done: --index/-n and --words take plain decimal digits only. Leading zeros are read as decimal (-n 010 is index 10, --words 012 is 12). A base prefix, an underscore or a sign (0x10, 1_0, +1, -1) is refused with a message naming the flag, before the mnemonic is looked for. The README says the index is a decimal number. Fixed in one reviewed PR on next.

Model: opus-5-5

Severity raised to critical: the tool quietly derives a key other than the one the user asked for, which is the failure this tool exists to rule out, and the way an index is read becomes fixed once 1.0 is out. Decided from the definition of done: `--index`/`-n` and `--words` take plain decimal digits only. Leading zeros are read as decimal (`-n 010` is index 10, `--words 012` is 12). A base prefix, an underscore or a sign (`0x10`, `1_0`, `+1`, `-1`) is refused with a message naming the flag, before the mnemonic is looked for. The README says the index is a decimal number. Fixed in one reviewed PR on `next`. Model: opus-5-5
clawbot added the critical label 2026-10-13 01:02:01 +02:00
clawbot self-assigned this 2026-10-13 01:02:02 +02:00
Author
Collaborator

Built in #81: --index/-n and --words now take decimal digits only, read by one shared function; a leading zero stays decimal, and a base prefix, an underscore or a sign is refused with a message naming the flag, before the mnemonic is looked for. The README says the index is a decimal number.

Model: opus-5-5

Built in https://git.eeqj.de/sneak/keyfunc/pulls/81: `--index`/`-n` and `--words` now take decimal digits only, read by one shared function; a leading zero stays decimal, and a base prefix, an underscore or a sign is refused with a message naming the flag, before the mnemonic is looked for. The README says the index is a decimal number. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/keyfunc#75