Skip to content

fix(documentai-toolbox): enable autoescape in export_hocr_str - #18140

Merged
parthea merged 1 commit into
googleapis:mainfrom
Samin061:hocr-autoescape
Aug 18, 2026
Merged

fix(documentai-toolbox): enable autoescape in export_hocr_str#18140
parthea merged 1 commit into
googleapis:mainfrom
Samin061:hocr-autoescape

Conversation

@Samin061

Copy link
Copy Markdown
Contributor

export_hocr_str builds its Jinja2 Environment without autoescape, so the title argument is written into the <title> element unescaped. A title such as </title><script>alert(1)</script> breaks out of the element and lands as raw script markup, producing invalid XML in an hOCR document that is meant to be valid XHTML rendered in a browser. The word and line text already pass through the escape filter, so enabling autoescape closes the remaining gap inside the helper while leaving the output byte-identical for normal input (existing golden-file tests are unchanged).

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

@Samin061
Samin061 requested a review from a team as a code owner August 18, 2026 13:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables autoescaping (autoescape=True) in the Jinja2 environment within export_hocr_str to prevent potential injection vulnerabilities, and adds a corresponding unit test test_export_hocr_str_escapes_title to verify that HTML/XML tags in the title are properly escaped. There are no review comments, so I have no feedback to provide.

@parthea parthea added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Aug 18, 2026
@parthea parthea self-assigned this Aug 18, 2026
@parthea parthea removed their assignment Aug 18, 2026
@parthea parthea removed kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Aug 18, 2026
@parthea
parthea enabled auto-merge (squash) August 18, 2026 14:52
@parthea

parthea commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Thanks @Samin061!

@hebaalazzeh hebaalazzeh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@parthea
parthea merged commit 0d671d2 into googleapis:main Aug 18, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants