Remove URL-unsafe characters from gen-secret charset

Remove ^, +, ~, :, @ from the allowed charset. The ^ character breaks
SQLAlchemy DATABASE_URL parsing, + becomes space in URL query strings,
: and @ are URL delimiters. The remaining charset (A-Za-z0-9._-) is
safe in URLs, database connection strings, YAML, JSON, and shell
without any encoding.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Paul O'Reilly
2026-03-28 21:29:08 +13:00
parent 8bd4c7253b
commit c470867039
3 changed files with 12 additions and 12 deletions

View File

@@ -57,12 +57,12 @@ echo
out=$("$GEN_SECRET" --dryrun 2>&1)
assert_eq "dryrun default length" \
'[dryrun] Would generate a 32-character secret from charset: [A-Za-z0-9._+\-:@^~]' \
'[dryrun] Would generate a 32-character secret from charset: [A-Za-z0-9._\-]' \
"$out"
out=$("$GEN_SECRET" -n 16 2>&1)
assert_eq "dryrun custom length" \
'[dryrun] Would generate a 16-character secret from charset: [A-Za-z0-9._+\-:@^~]' \
'[dryrun] Would generate a 16-character secret from charset: [A-Za-z0-9._\-]' \
"$out"
# --- Help ---
@@ -78,7 +78,7 @@ out=$("$GEN_SECRET" 2>&1)
rc=$?
assert_exit "default exits 0" 0 "$rc"
assert_eq "default length is 32" 32 "${#out}"
assert_match "default uses safe charset" '^[A-Za-z0-9._+:@^~-]+$' "$out"
assert_match "default uses safe charset" '^[A-Za-z0-9._-]+$' "$out"
# --- Custom length ---