fix(azure): guard against non-dict auth_settings in AppServiceAuthentication (CKV_AZURE_13)#7550
Open
AlexanderSanin wants to merge 1 commit into
Conversation
…ication When checking azurerm_windows_web_app or azurerm_linux_web_app resources from a Terraform plan JSON file, auth_settings[0] and auth_settings_v2[0] can be a StrNode (a str subclass) rather than a dict. Calling .get() on a StrNode raises TemplateAttributeError because StrNode.__getattr__ raises that error for any unknown attribute. Add isinstance(auth, dict) guards before the .get() calls in both the auth_settings and auth_settings_v2 code paths so the check returns FAILED instead of crashing. Closes bridgecrewio#7190 Signed-off-by: Oleksandr Sanin <alexaaander.sanin@gmail.com>
Author
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
CKV_AZURE_13(AppServiceAuthentication) when scanning Terraform plan JSON files whereauth_settings[0]orauth_settings_v2[0]is aStrNode(astrsubclass produced by the Terraform plan parser) rather than adict..get()on aStrNodetriggersStrNode.__getattr__, which raisesTemplateAttributeError: get is invalid.isinstance(auth, dict)guards before.get()calls in both theauth_settingsandauth_settings_v2code paths, matching the pattern already used in other Azure checks (e.g.AzureManagedDiskEncryption,NSGRulePortAccessRestricted).test_non_dict_auth_settings_does_not_crashthat directly exercises the crash path.Closes #7190
Test plan
TestAppServiceAuthentication::teststill passes (5 pass, 6 fail — unchanged)TestAppServiceAuthentication::test_non_dict_auth_settings_does_not_crashpasses — confirmsFAILEDis returned instead ofTemplateAttributeErrorwhenauth_settings[0]is a non-dict valuepython -m pytest tests/terraform/checks/resource/azure/test_AppServiceAuthentication.py -v