fix(arm): don't raise IndexError on malformed resourceId()/reference() calls - #7635
Open
ankit090701 wants to merge 1 commit into
Open
fix(arm): don't raise IndexError on malformed resourceId()/reference() calls#7635ankit090701 wants to merge 1 commit into
ankit090701 wants to merge 1 commit into
Conversation
…) calls
extract_resource_name_from_resource_id_func indexed resource_id.split(',')[1]
unconditionally, but its only caller (_create_explicit_edge, used while
building the ARM dependency graph) triggers it for any dependsOn entry that
merely contains the substring "resourceId(" - it does not verify the call
actually has the expected "resourceId(type, name, ...)" shape. A
single-argument or otherwise malformed resourceId() call therefore has no
comma to split on, and IndexError propagates out of graph building,
crashing the whole scan (checkov/common/parallelizer/parallel_runner.py
re-raises worker exceptions in the main process).
extract_resource_name_from_reference_func has the same class of bug: it
checks `'resourceId' in resource_name` (no trailing paren) but then
unconditionally indexes `resource_name.split('resourceId(', 1)[1]` (with
the paren). Any resource/variable name that merely contains "resourceId"
as a substring without being immediately followed by "(" - e.g.
resourceIdentifier - passes the check but fails the split, so this also
raises IndexError instead of falling through to the plain-reference
handling used by every other shape.
Add a length check before indexing in the first function, and tighten the
second function's guard to require the same substring the split expects.
Fixes bridgecrewio#7633
ankit090701
requested a deployment
to
scan-security
August 1, 2026 20:33 — with
GitHub Actions
Waiting
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.
Description
Reported as a pipeline crash (
IndexError: list index out of range, re-raised fromcheckov/common/parallelizer/parallel_runner.pyafter occurring in a worker process) that only happens when thearmframework is included in a scan.Root cause
Two functions in
checkov/arm/utils.py, both used while building the ARM dependency graph (checkov/arm/graph_builder/local_graph.py), index into astr.split(...)result without checking there are enough parts:extract_resource_name_from_resource_id_func- called from_create_explicit_edgefor anydependsOnentry containing the substring"resourceId(", regardless of whether the call actually has the assumedresourceId(type, name, ...)shape:A single-argument (or otherwise malformed)
resourceId()call has no comma to split on, so[1]raisesIndexError.extract_resource_name_from_reference_funchas a mismatched guard: it checks'resourceId' in resource_name(no trailing paren) but then unconditionally doesresource_name.split('resourceId(', 1)[1](with the paren). Any resource/variable name that merely contains"resourceId"as a substring without being immediately followed by"("- e.g.resourceIdentifier- passes the guard but fails the split, raisingIndexErrorinstead of falling through to the plain-reference handling every other shape uses.Fix
extract_resource_name_from_resource_id_func; fall back to the raw (cleaned) string if the split doesn't have the expected shape, rather than crashing.extract_resource_name_from_reference_func's guard to check for'resourceId('(matching what the subsequent split actually looks for), so the two can never disagree.Both changes are minimal and preserve existing behavior for every well-formed input (verified against the existing test cases).
Testing
test_extract_resource_name_from_resource_id_func(a new test - the function had no dedicated tests before) covering both the documented multi-argument shape and a three-argument nested-resource shape.test_extract_resource_name_from_resource_id_func_single_arg, reproducing the crash class from this issue with a single-argumentresourceId()call.test_extract_resource_name_from_reference_func_resource_id_substring_without_call, reproducing the second crash with a resource name (resourceIdentifier) that contains"resourceId"as a substring without a call.checkov/arm/utils.pychange: both new crash-reproducing tests fail withIndexError: list index out of rangeat the exact lines described above.tests/arm/suite (pytest tests/arm/): 211 passed. The only remaining issue (tests/arm/graph_builder/checks/test_yaml_policies.py) fails to even collect in my minimal Docker environment due to a missinggraph_frameworktest-parametrization setup unrelated to this change (nothing in this PR touches graph-framework/DB-connector selection).Fixes #7633