Repository navigation
fix: report clean error for Fn::GetAtt string form without an attribute - #4696
Merged
Merged
Conversation
A JSON string-form GetAtt without a dot (e.g. {"Fn::GetAtt":
"MyResource"}) split into a single-element list. The schema's minItems/
maxItems only constrain the array form, so the dotless string passed
validation and later indexing (value[1]) crashed with an IndexError.
Guard the string form and emit a clean validation error instead.
Fixes aws-cloudformation#4694
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4696 +/- ##
=======================================
Coverage 94.65% 94.65%
=======================================
Files 434 434
Lines 15558 15561 +3
Branches 3018 3019 +1
=======================================
+ Hits 14726 14729 +3
Misses 454 454
Partials 378 378
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add a pattern to the GetAtt function schema so a string-form GetAtt must contain a resource and an attribute separated by a dot. The resource segment is a CloudFormation logical id (alphanumeric); the attribute is left unconstrained so custom-resource attribute names (underscores, hyphens) and nested attributes are still accepted. The runtime guard is retained so a malformed value surfaces a clear message and can never reach the value[1] indexing that crashed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{"Fn::GetAtt": "MyResource"}(JSON string form without a.) crashed cfn-lint with an unhandledIndexError: list index out of range, surfaced asE1010 Exception 'list index out of range' raised while validating 'fn_getatt'.The string form is split on the first "." into
[resource, attribute]. The schema'sminItems/maxItemsonly constrain the array form (they are ignored for strings), so a dotless string produced a single-element list that passed validation, and_resolve_getattthen indexedvalue[1]and crashed.This fixes it in two complementary ways:
getatt.json): add apatternso the string form must contain a resource and an attribute separated by a dot. The resource segment is a CloudFormation logical id ([a-zA-Z0-9]+); the attribute is left unconstrained (.+) so custom-resource attribute names (underscores, hyphens) and nested attributes (.Outputs.X) are still accepted. The real per-resource attribute validation continues to happen in_resolve_getatt.GetAtt.py): a guard emits a clear message and returns before the crashingvalue[1]index, so a malformed value can never crash even if the schema is bypassed.The array form (
{"Fn::GetAtt": ["MyResource"]}) and the YAML shorthand (!GetAtt MyResource) were already handled byminItems: 2.Fixes #4694
Behavior
Before:
After:
Custom-resource attributes with non-alphanumerics (e.g.
MyCustom.my_attr-1) remain valid — verified againstmain.Testing
test/unit/rules/functions/test_getatt.py: dotless string (clean error) and a custom-resource attribute with underscores/hyphens (valid, guards against an over-strict pattern).pytest test/unit/rules/functions/— 279 pass.ruff check,ruff format --check,isort,mypy— all clean.