fix(skills): escape quotes/backslashes in YAML colon fixer, escape all 5 XML special chars#2126
Closed
agent-of-mkmeral wants to merge 1 commit intostrands-agents:mainfrom
Closed
Conversation
…e all 5 XML special chars Fix two bugs in the AgentSkills plugin discovered during adversarial testing: 1. _fix_yaml_colons now escapes backslashes and double quotes before wrapping values in double quotes. Previously, values like 'description: Use when: user says "hello"' would produce invalid YAML because the quotes were not escaped. 2. XML generation now escapes all 5 XML special characters (&, <, >, ", ') instead of only the 3 covered by the default xml.sax.saxutils.escape (which omits " and ').
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
During adversarial testing of the TypeScript skills PR (sdk-typescript#807), two bugs were discovered in the Python AgentSkills plugin. The TS implementation already handles these correctly — this PR brings Python to parity.
Changes
Bug 1:
_fix_yaml_colonsdoesn't escape quotes or backslashes (Medium)File:
src/strands/vended_plugins/skills/skill.pyThe YAML colon-quoting fallback wraps values in double quotes but didn't escape existing
"or\characters in the value first, producing invalid YAML:Also fails with Windows-style paths containing backslashes (
C:\Users\test:) which YAML interprets as escape sequences.Bug 2: XML escaping only covers 3 of 5 special characters (Low)
File:
src/strands/vended_plugins/skills/agent_skills.pyThe
_generate_skills_xmlmethod usedxml.sax.saxutils.escape()which only escapes&,<,>— but not"and'. While these are technically valid in XML element content, escaping them is safer and prevents edge cases with nested XML or attribute contexts. Added a helper_escape_xml()that passes extra entities to cover all 5 characters.Testing
cc @mkmeral