MOSIP-44222: Fixed security issue for PMS in EmailableReport where internal TestNG method names were exposed.#1883
Conversation
Signed-off-by: SradhaMohanty5899 <mohantysradha10@gmail.com>
WalkthroughReplaced ad-hoc method-name usage with a private helper Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java (1)
780-795:⚠️ Potential issue | 🟠 MajorEscape test case keys before writing HTML.
getTestCaseKeycan come from attributes/DTOs and is now written to HTML without escaping, which can break the report or allow HTML injection. UseUtils.escapeHtmlfor the displayed value.✅ Suggested fix
- String temp = uniqueIdentifier.isEmpty() ? getTestCaseKey(firstResult) : uniqueIdentifier; + String temp = uniqueIdentifier.isEmpty() ? getTestCaseKey(firstResult) : uniqueIdentifier; + String safeTemp = Utils.escapeHtml(temp); @@ - buffer.append("<td style=\"text-align:left;\"><a href=\"#m").append(scenarioIndex).append("\">") - .append(temp).append("</a></td>").append("<td style=\"text-align:left;\">") + buffer.append("<td style=\"text-align:left;\"><a href=\"#m").append(scenarioIndex).append("\">") + .append(safeTemp).append("</a></td>").append("<td style=\"text-align:left;\">") @@ - buffer.append("<tr class=\"").append(cssClass).append("\">") - .append("<td style=\"text-align:center;\"><a href=\"#m").append(scenarioIndex) - .append("\">").append(temp).append("</a></td></tr>"); + buffer.append("<tr class=\"").append(cssClass).append("\">") + .append("<td style=\"text-align:center;\"><a href=\"#m").append(scenarioIndex) + .append("\">").append(safeTemp).append("</a></td></tr>");
🤖 Fix all issues with AI agents
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java`:
- Around line 878-882: The fallback logic for TestCaseName only checks for null
so empty or whitespace values still display as blank; update the code around the
testCaseName assignment (the variable testCaseName obtained via
result.getAttribute("TestCaseName")) to treat blank/whitespace as missing by
trimming and/or using an isBlank check and then falling back to
result.getMethod().getMethodName() when testCaseName is null or blank. Ensure
you reference the same variable name testCaseName and the same fallback source
result.getMethod().getMethodName().
- Around line 1374-1387: In getTestCaseKey, guard against null/blank values
returned from TestCaseDTO.getTestCaseName() and fall back to
result.getMethod().getMethodName() if the dto name is null/empty; specifically,
when inspecting result.getParameters() and the first param is a TestCaseDTO,
retrieve dto.getTestCaseName() into a local String (e.g., dtoName), trim and
check it for null/empty before returning it, otherwise continue to the final
fallback. Also rename the local TestCaseName variable to follow Java conventions
(testCaseName).
🧹 Nitpick comments (1)
apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java (1)
1193-1211: Align sort order with the new test case key.
groupResultsnow groups bygetTestCaseKey, but the list is still sorted by method name. If keys don’t correlate with method names, identical keys might not be contiguous, which can split groups unexpectedly. Consider sorting by the same key you group by.♻️ Suggested refactor (RESULT_COMPARATOR)
protected static final Comparator<ITestResult> RESULT_COMPARATOR = new Comparator<ITestResult>() { `@Override` public int compare(ITestResult o1, ITestResult o2) { int result = o1.getTestClass().getName().compareTo(o2.getTestClass().getName()); if (result == 0) { - result = o1.getMethod().getMethodName().compareTo(o2.getMethod().getMethodName()); + String k1 = getTestCaseKey(o1); + String k2 = getTestCaseKey(o2); + result = k1.compareTo(k2); + if (result == 0) { + result = o1.getMethod().getMethodName().compareTo(o2.getMethod().getMethodName()); + } } return result; } };
apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java
Show resolved
Hide resolved
apitest-commons/src/main/java/io/mosip/testrig/apirig/report/EmailableReport.java
Show resolved
Hide resolved
Signed-off-by: SradhaMohanty5899 <mohantysradha10@gmail.com>
Summary by CodeRabbit
Bug Fixes
Refactor