Skip to content

Add software list export#155

Open
markcrivera wants to merge 1 commit into
mainfrom
feat/software-list-export
Open

Add software list export#155
markcrivera wants to merge 1 commit into
mainfrom
feat/software-list-export

Conversation

@markcrivera
Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Mark Rivera <mark.c.rivera@lmco.com>
@Amndeep7 Amndeep7 temporarily deployed to tir-feat-software-list--ylx6yi December 23, 2025 21:00 Inactive
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
4 Security Hotspots
5.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

for (const myVal of splitted) {
// allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
var softwareDetails = myVal.split("\n");
var mySoftware = softwareDetails[0].replace('"', '"');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of '"'.

Copilot Autofix

AI 5 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Comment on lines +221 to +226
var myVersion = myVal
.split("All Possible Versions")[1]
.split("\n")[0]
.split(":")[1]
.trim()
.replace('"', '"');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This replaces only the first occurrence of '"'.

Copilot Autofix

AI 5 months ago

General approach: when escaping characters in strings, either use a well-tested library or ensure that replacements cover all occurrences, typically using a regular expression with the g flag. Also, escape backslashes correctly where relevant. In this snippet, the two .replace('"', '"') calls are both incomplete and misleading; if they were changed later to something like .replace('"', '""'), they would only escape the first quote. The best fix is to either (1) remove these no-op replacements entirely, or (2) convert them to a correct global replacement that will work if the code is later updated to do real escaping.

Best minimal fix without changing functionality: since the current replacements do nothing (" -> "), removing them would not change runtime behavior at all. However, the intention appears to be to escape internal quotes before wrapping the values in double quotes for printName and printVersion. To both preserve current behavior and make the code robust for its likely intended purpose, I will replace the current replace calls with global-regex-based replacements that still map " to " (thus still a no-op) but follow the safe pattern. If the project later changes the replacement string to something else (e.g. \" or ""), all occurrences will then be handled correctly.

Concretely:

  • In server/utils/excelExport/nessusExport.ts, inside the branch if (pluginId == 178102):
    • Change var mySoftware = softwareDetails[0].replace('"', '"'); to use a global regex: replace(/"/g, '"').
    • Change the final .replace('"', '"') in the myVersion chain to .replace(/"/g, '"').

No new methods or imports are needed; this relies only on built-in String.prototype.replace with a regex.


Suggested changeset 1
server/utils/excelExport/nessusExport.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/utils/excelExport/nessusExport.ts b/server/utils/excelExport/nessusExport.ts
--- a/server/utils/excelExport/nessusExport.ts
+++ b/server/utils/excelExport/nessusExport.ts
@@ -216,14 +216,14 @@
       for (const myVal of splitted) {
         // allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
         var softwareDetails = myVal.split("\n");
-        var mySoftware = softwareDetails[0].replace('"', '"');
+        var mySoftware = softwareDetails[0].replace(/"/g, '"');
         if (mySoftware != "") {
           var myVersion = myVal
             .split("All Possible Versions")[1]
             .split("\n")[0]
             .split(":")[1]
             .trim()
-            .replace('"', '"');
+            .replace(/"/g, '"');
           var printName = '"' + mySoftware + '"';
           var printVersion = '"' + myVersion + '"';
           var theseSystems = addSoftwareSystem(
EOF
@@ -216,14 +216,14 @@
for (const myVal of splitted) {
// allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
var softwareDetails = myVal.split("\n");
var mySoftware = softwareDetails[0].replace('"', '"');
var mySoftware = softwareDetails[0].replace(/"/g, '"');
if (mySoftware != "") {
var myVersion = myVal
.split("All Possible Versions")[1]
.split("\n")[0]
.split(":")[1]
.trim()
.replace('"', '"');
.replace(/"/g, '"');
var printName = '"' + mySoftware + '"';
var printVersion = '"' + myVersion + '"';
var theseSystems = addSoftwareSystem(
Copilot is powered by AI and may make mistakes. Always verify output.
for (const myVal of splitted) {
// allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
var softwareDetails = myVal.split("\n");
var mySoftware = softwareDetails[0].replace('"', '"');

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '"' with itself.

Copilot Autofix

AI 5 months ago

In general, to fix “replacement of a substring with itself” you either (1) correct the replacement string to perform the intended transformation (e.g., escape or strip characters), or (2) remove the call entirely if no transformation is needed. Here, we do not have enough evidence of a specific intended transformation (escaping vs. stripping), but we know for certain the current replace('"', '"') calls are redundant. Removing them does not change runtime behavior (since they are already no-ops) but eliminates the defect and clarifies the code.

Concretely, in server/utils/excelExport/nessusExport.ts, within the if (pluginId == 178102) branch:

  • On line 219, replace var mySoftware = softwareDetails[0].replace('"', '"'); with var mySoftware = softwareDetails[0];.
  • On line 226, replace the chained .replace('"', '"') with nothing, i.e., let myVersion be the trimmed substring result directly.

No new imports, methods, or definitions are required; we are just simplifying existing expressions.

Suggested changeset 1
server/utils/excelExport/nessusExport.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/utils/excelExport/nessusExport.ts b/server/utils/excelExport/nessusExport.ts
--- a/server/utils/excelExport/nessusExport.ts
+++ b/server/utils/excelExport/nessusExport.ts
@@ -216,14 +216,13 @@
       for (const myVal of splitted) {
         // allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
         var softwareDetails = myVal.split("\n");
-        var mySoftware = softwareDetails[0].replace('"', '"');
+        var mySoftware = softwareDetails[0];
         if (mySoftware != "") {
           var myVersion = myVal
             .split("All Possible Versions")[1]
             .split("\n")[0]
             .split(":")[1]
-            .trim()
-            .replace('"', '"');
+            .trim();
           var printName = '"' + mySoftware + '"';
           var printVersion = '"' + myVersion + '"';
           var theseSystems = addSoftwareSystem(
EOF
@@ -216,14 +216,13 @@
for (const myVal of splitted) {
// allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
var softwareDetails = myVal.split("\n");
var mySoftware = softwareDetails[0].replace('"', '"');
var mySoftware = softwareDetails[0];
if (mySoftware != "") {
var myVersion = myVal
.split("All Possible Versions")[1]
.split("\n")[0]
.split(":")[1]
.trim()
.replace('"', '"');
.trim();
var printName = '"' + mySoftware + '"';
var printVersion = '"' + myVersion + '"';
var theseSystems = addSoftwareSystem(
Copilot is powered by AI and may make mistakes. Always verify output.
.split("\n")[0]
.split(":")[1]
.trim()
.replace('"', '"');

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '"' with itself.

Copilot Autofix

AI 5 months ago

In general, to fix this kind of problem you must ensure the replacement string is actually different from the search string and matches the intended transformation (e.g., escaping, normalization, or removal). Here the apparent goal is to safely embed software names and versions inside double quotes for output, which requires escaping any existing double quotes inside those strings.

The best targeted fix without changing existing behavior (except correcting this bug) is:

  • Change the .replace('"', '"') calls on both mySoftware and myVersion to escape embedded quotes by replacing each " with "", which is the standard way to escape quotes inside double-quoted fields in CSV/Excel contexts.
  • Use a global replacement so all occurrences of " are handled, not just the first one.

Concretely in server/utils/excelExport/nessusExport.ts:

  • At line 219, change var mySoftware = softwareDetails[0].replace('"', '"'); to var mySoftware = softwareDetails[0].replace(/"/g, '""');.
  • At line 226, change .replace('"', '"'); to .replace(/"/g, '""');.

No new imports or helper methods are needed; this uses built-in JavaScript String.prototype.replace with a regex literal.

Suggested changeset 1
server/utils/excelExport/nessusExport.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/server/utils/excelExport/nessusExport.ts b/server/utils/excelExport/nessusExport.ts
--- a/server/utils/excelExport/nessusExport.ts
+++ b/server/utils/excelExport/nessusExport.ts
@@ -216,14 +216,14 @@
       for (const myVal of splitted) {
         // allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
         var softwareDetails = myVal.split("\n");
-        var mySoftware = softwareDetails[0].replace('"', '"');
+        var mySoftware = softwareDetails[0].replace(/"/g, '""');
         if (mySoftware != "") {
           var myVersion = myVal
             .split("All Possible Versions")[1]
             .split("\n")[0]
             .split(":")[1]
             .trim()
-            .replace('"', '"');
+            .replace(/"/g, '""');
           var printName = '"' + mySoftware + '"';
           var printVersion = '"' + myVersion + '"';
           var theseSystems = addSoftwareSystem(
EOF
@@ -216,14 +216,14 @@
for (const myVal of splitted) {
// allObjects += myVal.substring(0, myVal.indexOf("\n")) + "\n";
var softwareDetails = myVal.split("\n");
var mySoftware = softwareDetails[0].replace('"', '"');
var mySoftware = softwareDetails[0].replace(/"/g, '""');
if (mySoftware != "") {
var myVersion = myVal
.split("All Possible Versions")[1]
.split("\n")[0]
.split(":")[1]
.trim()
.replace('"', '"');
.replace(/"/g, '""');
var printName = '"' + mySoftware + '"';
var printVersion = '"' + myVersion + '"';
var theseSystems = addSoftwareSystem(
Copilot is powered by AI and may make mistakes. Always verify output.
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