fix(writers/python): prevent code injection via x-ms-enum description#7735
Open
MIchaelMainer wants to merge 4 commits into
Open
fix(writers/python): prevent code injection via x-ms-enum description#7735MIchaelMainer wants to merge 4 commits into
MIchaelMainer wants to merge 4 commits into
Conversation
… newlines The RemoveInvalidDescriptionCharacters method in PythonConventionService did not strip newline characters (\r\n, \r, \n). A malicious OpenAPI spec could inject arbitrary Python code via x-ms-enum description fields by embedding newlines that break out of inline comments (# ...) or docstrings. This fix replaces newlines with spaces, keeping all description content on a single line where it remains safely within comments/docstrings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… newlines The RemoveInvalidDescriptionCharacters method in PythonConventionService did not strip newline characters (\r\n, \r, \n). A malicious OpenAPI spec could inject arbitrary Python code via x-ms-enum description fields by embedding newlines that break out of inline comments (# ...) or docstrings. This fix replaces newlines with spaces, keeping all description content on a single line where it remains safely within comments/docstrings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
baywet
previously approved these changes
May 26, 2026
Member
|
@MIchaelMainer some unit tests are failing. Could be transient. |
…b.com/microsoft/kiota into fix/python-enum-description-injection
baywet
reviewed
May 27, 2026
| - "**" | ||
| --- | ||
|
|
||
| # Pre-Commit Testing Requirements |
Member
There was a problem hiding this comment.
sorry, what I meant was to amend this one.
that one
https://github.com/microsoft/kiota/blob/main/.github/skills/codegen-literal-security-scan/SKILL.md
this one
https://github.com/microsoft/kiota/blob/main/.github/agents/codegen-security-guardian.agent.md
And I think the reason why they didn't get looped in is because we don't have .github/copilot-instructions.md on this repository. (contrary to other repositories I work on)
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.
Fixes a code injection vulnerability in the Python writer where malicious x-ms-enum description fields containing newline characters could break out of
inline comments (# ...) or docstrings and inject arbitrary Python code into generated output.
Changes
triple-quote replacements.
Root Cause
The RemoveInvalidDescriptionCharacters method only handled backslash and triple-quote escaping but did not strip newline characters. Since Python
inline comments are single-line (# ...), an embedded newline would terminate the comment and allow subsequent text to execute as Python code.
Security Impact
A malicious OpenAPI specification could inject arbitrary Python code into generated SDK clients via the x-ms-enum extension's description field.