[Fix] nvm_sanitize_auth_header: strip newlines, so wrapped base64 credentials work
`sed` works one line at a time, so the allowlist never removed newlines inside `NVM_AUTH_HEADER`. A `Basic` credential built with GNU `base64`, which wraps its output at 76 columns, therefore reached the downloader split across several lines, and authentication failed (wget rejects such a header outright). Filter with `tr -cd` instead, using the same set of allowed characters, so CR and LF are deleted like any other disallowed character and a wrapped credential is joined back into one line Discovered by Anthropic's OSS Scanner, as bug ANT-2026-W1E9TAK3; the scanner correctly classified it as not a vulnerability.
This commit is contained in:
2 files changed
+13
-2
No files matched your search
@@ -217,8 +217,10 @@ nvm_sanitize_auth_header() {
|
||||
# `Basic <base64>` and `Bearer <token>` survive intact.
|
||||
# '~' is also allowed, completing RFC 7235 `token68` (and thus RFC 6750
|
||||
# `b64token`), so opaque Bearer tokens containing it are not corrupted.
|
||||
# Note: '-' must be at the end of the bracket expression to be treated as a literal.
|
||||
nvm_echo "$1" | command sed 's/[^a-zA-Z0-9 :_.+/=~-]//g'
|
||||
# Note: '-' must be at the end of the set to be treated as a literal.
|
||||
# `tr`, not `sed`: sed is line-based and would keep newlines, eg from a
|
||||
# `base64` credential that was wrapped at 76 columns.
|
||||
nvm_echo "$1" | command tr -cd 'a-zA-Z0-9 :_.+/=~-'
|
||||
}
|
||||
|
||||
nvm_has_system_node() {
|
||||
|
||||
Reference in new issue
Block a user