Skip to content

fix(azure): guard against non-dict auth_settings in AppServiceAuthentication (CKV_AZURE_13)#7550

Open
AlexanderSanin wants to merge 1 commit into
bridgecrewio:mainfrom
AlexanderSanin:fix/app-service-auth-template-attribute-error
Open

fix(azure): guard against non-dict auth_settings in AppServiceAuthentication (CKV_AZURE_13)#7550
AlexanderSanin wants to merge 1 commit into
bridgecrewio:mainfrom
AlexanderSanin:fix/app-service-auth-template-attribute-error

Conversation

@AlexanderSanin
Copy link
Copy Markdown

Summary

  • Fixes a crash in CKV_AZURE_13 (AppServiceAuthentication) when scanning Terraform plan JSON files where auth_settings[0] or auth_settings_v2[0] is a StrNode (a str subclass produced by the Terraform plan parser) rather than a dict.
  • Calling .get() on a StrNode triggers StrNode.__getattr__, which raises TemplateAttributeError: get is invalid.
  • Added isinstance(auth, dict) guards before .get() calls in both the auth_settings and auth_settings_v2 code paths, matching the pattern already used in other Azure checks (e.g. AzureManagedDiskEncryption, NSGRulePortAccessRestricted).
  • Added a regression test test_non_dict_auth_settings_does_not_crash that directly exercises the crash path.

Closes #7190

Test plan

  • Existing test TestAppServiceAuthentication::test still passes (5 pass, 6 fail — unchanged)
  • New test TestAppServiceAuthentication::test_non_dict_auth_settings_does_not_crash passes — confirms FAILED is returned instead of TemplateAttributeError when auth_settings[0] is a non-dict value
  • Run: python -m pytest tests/terraform/checks/resource/azure/test_AppServiceAuthentication.py -v

…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>
@AlexanderSanin
Copy link
Copy Markdown
Author

Hey @maxamel @Saarett @AdamDev. Could you, please, have a look at this?

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.

Crash with policy CKV_AZURE_13

1 participant