pawarprasad123 commented on code in PR #732:
URL: https://github.com/apache/atlas/pull/732#discussion_r3824993829
##########
dashboard/jest.config.js:
##########
@@ -36,6 +36,7 @@ const config = {
// Module name mapping for path aliases
moduleNameMapper: {
Review Comment:
verify this:
Is this moduleNameMapper still required? On Node 22.22.x with the current
Jest/babel setup, all 4790 tests pass without it. If it is required for CI or
older Node, please note that in the PR description. If not, removing the mock
would let unit tests exercise the real upgraded library.
##########
dashboard/jest.config.js:
##########
Review Comment:
[email protected] requires Node >=22.12.0. The project’s Maven config
already uses Node 22.22.1, but consider adding "engines": { "node": ">=22.12.0"
} here so local dev environments are aligned.
##########
dashboard/src/__mocks__/sanitize-html.ts:
##########
@@ -0,0 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+const sanitizeHtml = (html: string) => typeof html === 'string' ?
html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '') : html;
Review Comment:
Add tests in Utils.test.ts that use jest.unmock('sanitize-html') (or a
dedicated integration describe block) to test the real library, with both
positive and negative XSS cases aligned with sanitizeHtmlContent’s config in
Utils.ts:
```
const sanitizeHtmlContent = (htmlContent: HTMLElement | string | any) => {
const content =
typeof htmlContent === "string"
? htmlContent
: htmlContent?.toString?.() ?? "";
const cleanContent = sanitizeHtml(content, {
allowedTags: [
"b", "em", "strong", "u", "a", "ul", "ol", "li", "p",
"strike", "h1", "h2", "h3", "h4"
],
allowedAttributes: { a: ["href"] },
allowedSchemesByTag: { a: ["http", "https", "mailto"] }
});
return cleanContent;
};
```
The mock only strips <script> tags and ignores allowedTags,
allowedAttributes, and allowedSchemesByTag. Tests using sanitizeHtmlContent
therefore don’t validate the upgraded library. Consider either:
Making the mock honor the same allowlist as Utils.ts, or
Adding integration tests with jest.unmock('sanitize-html') that hit the real
2.17.6 package.
Please format this as a multi-line function for readability, and add an
optional _options parameter to match the real sanitize-html API.
--
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]