Repository navigation
Commit 0d671d2
authored
fix(documentai-toolbox): enable autoescape in export_hocr_str (#18140)
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](https://github.com/googleapis/google-cloud-python/issues)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)1 parent 3ba7d02 commit 0d671d2
2 files changed
Lines changed: 19 additions & 1 deletion
File tree
- packages/google-cloud-documentai-toolbox
- google/cloud/documentai_toolbox/wrappers
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
943 | 943 | | |
944 | 944 | | |
945 | 945 | | |
946 | | - | |
| 946 | + | |
| 947 | + | |
947 | 948 | | |
948 | 949 | | |
949 | 950 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
949 | 949 | | |
950 | 950 | | |
951 | 951 | | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
952 | 969 | | |
953 | 970 | | |
954 | 971 | | |
| |||
0 commit comments