docs: clarify stdlib xml vs defusedxml usage at every import site - #1860
Open
jacalata wants to merge 1 commit into
Open
docs: clarify stdlib xml vs defusedxml usage at every import site#1860jacalata wants to merge 1 commit into
jacalata wants to merge 1 commit into
Conversation
All XML parsing of server responses already uses defusedxml (safe against XXE/entity expansion). Stdlib xml is retained only for building outbound request bodies (no defusedxml equivalent) and for the ParseError exception type (which defusedxml raises unchanged). Added inline comments at each import site so future contributors don't replace these with defusedxml unnecessarily, and updated pyproject.toml dependency comment to explain the split. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Motivation
TSC uses both
xml.etree.ElementTree(stdlib) anddefusedxml.ElementTreeacross the codebase, and the pattern isn't obvious from a fresh reading.
Frontier AI's recent security analysis of all OSS Salesforce repos flagged
these stdlib
xml.etree.ElementTreeimports as a potential XXE concern.On investigation, every parsing path (
from_response,from_xmlinputs)already uses
defusedxml.fromstringfor XXE safety; stdlibxml.etree.ElementTreeis retained only for building outbound requestbodies (
Element/SubElement/tostring) and as a type annotationfor already-parsed inputs. defusedxml doesn't provide a builder
equivalent, so we can't simplify by using it everywhere.
Inline comments answer the security-analysis question at each import
site so future audits (Frontier AI or human) can confirm the intent
without re-tracing every usage, and so a well-meaning "swap stdlib for
defusedxml" cleanup doesn't accidentally break outbound XML building.
Behavior change
Docs only.
import xml.etree.ElementTree ...line(21 files) explaining the intent.
defusedxmlline inpyproject.tomldescribingthe same split.
Test plan
black --checkclean.🤖 Generated with Claude Code