gemini-code-assist[bot] commented on code in PR #38949:
URL: https://github.com/apache/beam/pull/38949#discussion_r3421453062
##########
website/www/site/assets/js/bootstrap.js:
##########
@@ -1550,11 +1577,26 @@ if (typeof jQuery === 'undefined') {
.css(isVertical ? 'top' : 'left', '')
}
+ function sanitizeHtml(string) {
+ if (typeof DOMPurify !== 'undefined' && typeof string === 'string') {
+ return DOMPurify.sanitize(string)
+ }
+ if (typeof string === 'string') {
+ return string
+ .replace(/&/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''')
+ }
+ return string
+ }
Review Comment:

The fallback implementation of `sanitizeHtml` when `DOMPurify` is undefined
escapes all HTML characters (such as `<`, `>`, `&`, etc.). This completely
breaks the functionality of the `html: true` option for tooltips and popovers,
as any intended HTML markup (e.g., `<strong>`, `<a>`) will be rendered as plain
text showing the raw tags to the user.
If `DOMPurify` is not guaranteed to be loaded on all pages where tooltips
are used, this change will introduce visual regressions.
**Recommendation:**
If `DOMPurify` is not available, return the string unmodified to avoid
breaking existing HTML tooltips, and ensure `DOMPurify` is loaded in
environments where security sanitization is strictly required.
```javascript
function sanitizeHtml(string) {
if (typeof DOMPurify !== 'undefined' && typeof string === 'string') {
return DOMPurify.sanitize(string)
}
return string
}
```
##########
website/www/site/assets/js/bootstrap/tooltip.js:
##########
@@ -302,11 +302,26 @@
.css(isVertical ? 'top' : 'left', '')
}
+ function sanitizeHtml(string) {
+ if (typeof DOMPurify !== 'undefined' && typeof string === 'string') {
+ return DOMPurify.sanitize(string)
+ }
+ if (typeof string === 'string') {
+ return string
+ .replace(/&/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''')
+ }
+ return string
+ }
Review Comment:

The fallback implementation of `sanitizeHtml` when `DOMPurify` is undefined
escapes all HTML characters (such as `<`, `>`, `&`, etc.). This completely
breaks the functionality of the `html: true` option for tooltips and popovers,
as any intended HTML markup (e.g., `<strong>`, `<a>`) will be rendered as plain
text showing the raw tags to the user.
If `DOMPurify` is not guaranteed to be loaded on all pages where tooltips
are used, this change will introduce visual regressions.
**Recommendation:**
If `DOMPurify` is not available, return the string unmodified to avoid
breaking existing HTML tooltips, and ensure `DOMPurify` is loaded in
environments where security sanitization is strictly required.
```javascript
function sanitizeHtml(string) {
if (typeof DOMPurify !== 'undefined' && typeof string === 'string') {
return DOMPurify.sanitize(string)
}
return string
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]