fix(deploy-on-aws): resolve AttributeError from ET.Element type annotations in diagram scripts - #273
Open
iamharshtita wants to merge 1 commit into
Conversation
…ations defusedxml.ElementTree does not expose Element or ElementTree — it wraps only the parsing functions (parse, fromstring, iterparse) for security. Using ET.Element as a type annotation causes an AttributeError at import time on Python 3.10+ where annotations are evaluated eagerly, crashing all diagram post-processing scripts before any function is called. This affects all agent platforms (Claude Code, Codex, Cursor, Kiro) since the crash is in the Python scripts themselves, not the agent runtime. Fix: import Element and ElementTree from xml.etree.ElementTree for type annotations only. The defusedxml import is retained for all actual XML parsing calls (ET.parse, ET.fromstring, ET.iterparse) which is where the Bandit B314/B405 and Semgrep XXE security requirements apply. The Element and ElementTree classes carry no parsing security risk. Affected scripts: - scripts/lib/fix_step_badges.py - scripts/lib/fix_icon_colors.py - scripts/lib/fix_nesting.py - scripts/lib/post_process_drawio.py Validated: all 4 scripts import cleanly, fix_step_badges runs against example diagrams, and all 125 existing tests pass. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.
iamharshtita
requested review from
a team,
arnewouters,
krokoko and
rshevchuk-git
September 11, 2026 22:01
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
defusedxml.ElementTreewraps only the parsing functions (parse,fromstring,iterparse) — it does not exposeElementorElementTreeas attributes. UsingET.ElementandET.ElementTreeas type annotations causes anAttributeErrorat import time on Python 3.10+, where annotations are evaluated eagerly. This crashes all four diagram post-processing scripts before any function is called, affecting every agent platform (Claude Code, Codex, Cursor, Kiro).The fix imports
ElementandElementTreefromxml.etree.ElementTreefor type annotations only. Thedefusedxmlimport is retained for all actual XML parsing calls (ET.parse,ET.fromstring,ET.iterparse) where the Bandit B314/B405 and Semgrep XXE security requirements apply. TheElementandElementTreeclasses are not parsers and carry no XXE risk.Related
Changes
scripts/lib/fix_step_badges.py— addfrom xml.etree.ElementTree import Element, ElementTree, replace allET.Element→ElementandET.ElementTree→ElementTreescripts/lib/fix_icon_colors.py— same fixscripts/lib/fix_nesting.py— same fixscripts/lib/post_process_drawio.py— same fixvalidate_drawio.pyanddrawio_url.pyare unaffected — they use onlyET.parse,ET.fromstring,ET.ParseError, andET.iterparsewhich are all validdefusedxmlexports.All 4 scripts import cleanly after the fix,
fix_step_badges.pyruns successfully against example diagrams, and all 125 existing tests pass.Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.