Skip to content

fix: reject empty and newline-terminated region names in validate_region_name - #3790

Open
mturac wants to merge 1 commit into
boto:developfrom
mturac:fix/issue-3786
Open

fix: reject empty and newline-terminated region names in validate_region_name#3790
mturac wants to merge 1 commit into
boto:developfrom
mturac:fix/issue-3786

Conversation

@mturac

@mturac mturac commented Sep 2, 2026

Copy link
Copy Markdown

fixes #3786

tightened the host-label regex in validate_region_name (botocore/utils.py:1338):

  • {,63} changed to {1,63} — rejects empty string, which isnt a valid host label
  • $ changed to \Z — rejects trailing newlines (python's $ matches before a trailing \n)

the validator runs on S3 cross-region redirect path where region comes from server-controlled headers. practical severity is low (downstream http.client catches control chars, and empty region still resolves under amazonaws.com), but function's contract says "valid host label" and these inputs violate that.

added TestValidateRegionName with 8 tests covering valid regions, empty string, trailing newline, spaces, leading/trailing hyphens, numeric-only, and None. verified with the exact reproduction script from the issue.

…ion_name

The host-label regex accepted two inputs that are not valid host
labels: the empty string (because {,63} permits zero repetitions)
and any region ending in \n (because $ matches before a trailing
newline in Python).  Change the quantifier to {1,63} and the
end anchor to \Z so both cases now raise InvalidRegionError.

Add TestValidateRegionName with explicit coverage for the
previously-accepted inputs and the existing rejection cases.

Closes boto#3786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validate_region_name accepts empty and trailing-newline region names (contradicts its docstring)

1 participant