bip32: disallow paths with a leading m but without a following slash
What changed, and why it matters
This commit tightens how the library parses BIP32 key derivation paths. Previously, a string like 'm0' or 'm*' was accepted as if the 'm' were silently ignored, which could let an attacker trick a wallet into deriving keys from a different path than the user intended. The fix now rejects any path that starts with 'm' or 'M' but is not followed by a slash.
Treat as a low-to-moderate correctness/security fix. Users should upgrade and audit any code that constructs BIP32 paths without a slash after 'm'/'M', since such paths will now fail. Wallet developers should ensure path strings are normalized before passing to libwally.
Security signals we found
Input validation bypass in BIP32 path parser
Ambiguous path parsing could change derivation semantics
Potential key derivation from attacker-controlled path string
No explicit security framing in commit message
Evidence from the diff
In src/bip32.c, path_from_str_n() previously skipped a leading ‘m’/’M’ and then optionally skipped a following ‘/’. Because the slash was optional, inputs such as ‘m0’ or ‘m’ were parsed as bare paths ‘0’ or ‘’. The patch makes a leading ‘m’/’M’ require a subsequent ‘/’; otherwise it jumps to fail. Tests for ‘m*’ and ‘m0’ are added to confirm rejection.
Changed components
src/bip32.cBIP32 path parsing function path_from_str_n()libwally-core BIP32 key derivation APIInspect captured patch +5 / −1
### src/bip32.c
@@ -231,8 +231,10 @@ static int path_from_str_n(const char *str, size_t str_len,
size_t start = i;
if (i < str_len && (str[i] == 'm' || (allow_upper && str[i] == 'M')))
++i; /* Skip */
- if (i < str_len && str[i] == '/')
+ if (i < str_len && str[i] == '/') {
++i; /* Skip */
+ } else if (i == start + 1)
+ goto fail; /* Leading m with no following slash */
if (start == i)
*features |= BIP32_PATH_IS_BARE;
}
### src/test/test_bip32.py
@@ -594,6 +594,8 @@ def get_paths(path):
('m', 0, 0), # Empty resulting path (1)
('m/', 0, 0), # Empty resulting path (2)
('/', 0, 0), # Empty resulting path (3)
+ ('m*', 0, 0), # Wildcard without path
+ ('m0', 0, 0), # M without seperator
('M/1', 0, 0), # Uppercase M without flag
('m/1H', 0, 0), # Uppercase H without flag
('//', 0, 0), # Trailing slash (1)Why this scored 40/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.