Skip to content

Fix TypeError in s3 error handler when Error.Message is None#10355

Open
omghante wants to merge 1 commit into
aws:developfrom
omghante:fix/10161-s3errormsg-nonetype-crash
Open

Fix TypeError in s3 error handler when Error.Message is None#10355
omghante wants to merge 1 commit into
aws:developfrom
omghante:fix/10161-s3errormsg-nonetype-crash

Conversation

@omghante
Copy link
Copy Markdown

Description

Fix TypeError: argument of type 'NoneType' is not iterable in awscli/customizations/s3errormsg.py when S3-compatible endpoints return error responses with empty <Message></Message> XML elements.

Fixes #10161

Root Cause

S3-compatible endpoints (Ceph RadosGW, Hetzner, MinIO) may return valid XML error responses with empty <Message> elements. Python's ElementTree parses empty elements as None (i.e., .text = None), and botocore's error parsing path in _replace_nodes() does not normalize None to "". This causes the parsed response dict to contain {'Error': {'Message': None}}.

The _is_sigv4_error_message() and _is_kms_sigv4_error_message() functions then perform 'substring' in None, which raises:

TypeError: argument of type 'NoneType' is not iterable

Key Python gotcha: .get('Message', '') returns the default '' only when the key is absent. When the key exists with value None, .get() returns None.

Changes

  • Use or '' coalescing in _is_sigv4_error_message(), _is_permanent_redirect_message(), and _is_kms_sigv4_error_message() to handle None values safely
  • Guard enhance_error_msg() body against None Message and missing Endpoint in the PermanentRedirect code path
  • Add 6 unit tests covering None Message, None Code, empty string Message, and PermanentRedirect with None Message

Testing

  • All 5 existing tests pass without modification zero regressions
  • 6 new tests validate the fix across all vulnerable code paths
  • pytest tests/unit/customizations/test_s3errormsg.py -v 11 passed
  • No behavioral change for AWS S3 (AWS always returns non-empty Message content)

Credit

Root cause analysis by @sfwester in #10161.

S3-compatible endpoints (Ceph, MinIO, Hetzner) may return XML error
responses with empty <Message></Message> elements. Python's
ElementTree parses these as None, causing botocore to set
Error.Message to None in the parsed response dict.

The _is_sigv4_error_message() and _is_kms_sigv4_error_message()
functions use the in operator to check if a substring exists in
the message, which raises TypeError when the message is None.

Use or-coalescing to normalize None values to empty strings
before performing containment checks. Also guard the
enhance_error_msg() body against None Message and missing Endpoint
in the PermanentRedirect path.

Fixes aws#10161
@omghante omghante requested a review from a team as a code owner May 27, 2026 15:20
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.

aws: [ERROR]: argument of type 'NoneType' is not a container or iterable

1 participant