Skip to content

Conversation

@arnayv-47
Copy link
Contributor

No description provided.

PrashantKF and others added 30 commits June 13, 2025 23:36
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
kkmoghe-gsa and others added 27 commits June 13, 2025 23:54
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
Signed-off-by: Kedar M <kedar.moghe@gsa.gov>
@arnayv-47 arnayv-47 requested a review from PrashantKF June 17, 2025 17:22
@arnayv-47 arnayv-47 self-assigned this Jun 17, 2025
</script>
{% endif %}

<script src="https://code.jquery.com/jquery-3.6.0.min.js" type="text/javascript"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source Medium

Script loaded from content delivery network with no integrity check.
//console.log("Total results are : " + totalResults);

document.getElementById('search-params').innerHTML = encodeHTML(urlParams.get('query'));
document.getElementById("search-keyword").innerHTML = urlParams.get("query");

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.

Copilot Autofix

AI 5 months ago

To fix the issue, the user-provided value from urlParams.get("query") must be sanitized or encoded before being assigned to innerHTML. The best approach is to use a contextual output encoding function, such as encodeHTML, to ensure that any potentially malicious characters are escaped. This prevents the execution of scripts embedded in the query parameter.

Steps to fix:

  1. Apply the encodeHTML function to sanitize the urlParams.get("query") value before assigning it to innerHTML on line 45.
  2. Ensure that the encodeHTML function is defined and properly escapes HTML special characters.

Suggested changeset 1
assets/js/search.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/assets/js/search.js b/assets/js/search.js
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -44,3 +44,3 @@
     document.getElementById('search-params').innerHTML = encodeHTML(urlParams.get('query'));
-    document.getElementById("search-keyword").innerHTML = urlParams.get("query");
+    document.getElementById("search-keyword").innerHTML = encodeHTML(urlParams.get("query"));
     document.getElementById("results-count").innerHTML = totalResults;
EOF
@@ -44,3 +44,3 @@
document.getElementById('search-params').innerHTML = encodeHTML(urlParams.get('query'));
document.getElementById("search-keyword").innerHTML = urlParams.get("query");
document.getElementById("search-keyword").innerHTML = encodeHTML(urlParams.get("query"));
document.getElementById("results-count").innerHTML = totalResults;
Copilot is powered by AI and may make mistakes. Always verify output.

pagerLinks += '<div class="usa-footer__contact-info grid-row grid-gap"><div class="grid-col-auto"><p class="margin-top-0">Powered by <strong>Search.gov</strong></p></div></div>';

pager.innerHTML = pagerLinks;

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.

Copilot Autofix

AI 5 months ago

To fix the issue, we need to ensure that any user-controlled input is properly sanitized or encoded before being inserted into the DOM. The best approach here is to use the encodeHTML function (already defined in the code) to escape special characters in the page parameter and any other user-controlled data before concatenating it into pagerLinks. This will prevent malicious scripts from being executed.

Specifically:

  1. Use encodeHTML to sanitize the page parameter and any other user-controlled values before they are added to pagerLinks.
  2. Replace all instances where page or other user-controlled data is directly concatenated into HTML strings with their sanitized versions.

Suggested changeset 1
assets/js/search.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/assets/js/search.js b/assets/js/search.js
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -103,3 +103,3 @@
       if (page > 1){
-          pagerLinks += '<a href="' + getLinkToPage(1) + '" aria-label="First page" class="pager-button">First</a>';
+          pagerLinks += '<a href="' + encodeHTML(getLinkToPage(1)) + '" aria-label="First page" class="pager-button">First</a>';
       }
@@ -112,6 +112,6 @@
       for (var i = start; i < page; i++) {
-          pagerLinks += '<a href="' + getLinkToPage(i) + '" aria-label="Page ' + i + '" class="pager-button">' + i + '</a>';
+          pagerLinks += '<a href="' + encodeHTML(getLinkToPage(i)) + '" aria-label="Page ' + encodeHTML(i.toString()) + '" class="pager-button">' + encodeHTML(i.toString()) + '</a>';
       }
 
-      pagerLinks += '<span class="margin-2, pager-button-current">Page ' + page + " of " + totalPages + "</span>";
+      pagerLinks += '<span class="margin-2, pager-button-current">Page ' + encodeHTML(page.toString()) + " of " + encodeHTML(totalPages.toString()) + "</span>";
       
@@ -119,3 +119,3 @@
       for (var j = (1*page) + 1; j <= end; j++) {
-          pagerLinks += '<a href="' + getLinkToPage(j) + '" aria-label="Page ' + j + '" class="pager-button">' + j + '</a>';
+          pagerLinks += '<a href="' + encodeHTML(getLinkToPage(j)) + '" aria-label="Page ' + encodeHTML(j.toString()) + '" class="pager-button">' + encodeHTML(j.toString()) + '</a>';
       }
@@ -127,3 +127,3 @@
       if( totalPages > 1 && page < totalPages){
-          pagerLinks += '<a href="' + getLinkToPage(totalPages) + '" aria-label="Last page" class="pager-button">Last</a>';
+          pagerLinks += '<a href="' + encodeHTML(getLinkToPage(totalPages)) + '" aria-label="Last page" class="pager-button">Last</a>';
       }		
EOF
@@ -103,3 +103,3 @@
if (page > 1){
pagerLinks += '<a href="' + getLinkToPage(1) + '" aria-label="First page" class="pager-button">First</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(1)) + '" aria-label="First page" class="pager-button">First</a>';
}
@@ -112,6 +112,6 @@
for (var i = start; i < page; i++) {
pagerLinks += '<a href="' + getLinkToPage(i) + '" aria-label="Page ' + i + '" class="pager-button">' + i + '</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(i)) + '" aria-label="Page ' + encodeHTML(i.toString()) + '" class="pager-button">' + encodeHTML(i.toString()) + '</a>';
}

pagerLinks += '<span class="margin-2, pager-button-current">Page ' + page + " of " + totalPages + "</span>";
pagerLinks += '<span class="margin-2, pager-button-current">Page ' + encodeHTML(page.toString()) + " of " + encodeHTML(totalPages.toString()) + "</span>";

@@ -119,3 +119,3 @@
for (var j = (1*page) + 1; j <= end; j++) {
pagerLinks += '<a href="' + getLinkToPage(j) + '" aria-label="Page ' + j + '" class="pager-button">' + j + '</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(j)) + '" aria-label="Page ' + encodeHTML(j.toString()) + '" class="pager-button">' + encodeHTML(j.toString()) + '</a>';
}
@@ -127,3 +127,3 @@
if( totalPages > 1 && page < totalPages){
pagerLinks += '<a href="' + getLinkToPage(totalPages) + '" aria-label="Last page" class="pager-button">Last</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(totalPages)) + '" aria-label="Last page" class="pager-button">Last</a>';
}
Copilot is powered by AI and may make mistakes. Always verify output.
//console.log("Total results are : " + totalResults);

document.getElementById('search-params').innerHTML = encodeHTML(urlParams.get('query'));
document.getElementById("search-keyword").innerHTML = urlParams.get("query");

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.

Copilot Autofix

AI 5 months ago

To fix the issue, the user-provided input (urlParams.get("query")) must be sanitized or encoded before being inserted into the DOM. The best approach is to use a function that performs contextual output encoding to ensure that any special characters in the input are properly escaped. This prevents malicious scripts from being executed.

The fix involves:

  1. Introducing a utility function, encodeHTML, to encode special characters in the input.
  2. Replacing the direct use of urlParams.get("query") in innerHTML with the encoded version of the input.

Changes are required in the file search/index.html:

  • Add the encodeHTML function.
  • Update line 48 to use encodeHTML(urlParams.get("query")).

Suggested changeset 1
search/index.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/search/index.html b/search/index.html
--- a/search/index.html
+++ b/search/index.html
@@ -14,2 +14,9 @@
   
+  function encodeHTML(str) {
+    return str.replace(/&/g, "&amp;")
+              .replace(/</g, "&lt;")
+              .replace(/>/g, "&gt;")
+              .replace(/"/g, "&quot;")
+              .replace(/'/g, "&#39;");
+  }
   
@@ -47,3 +54,3 @@
       document.getElementById('search-params').innerHTML = encodeHTML(urlParams.get('query'));
-      document.getElementById("search-keyword").innerHTML = urlParams.get("query");
+      document.getElementById("search-keyword").innerHTML = encodeHTML(urlParams.get("query"));
       document.getElementById("results-count").innerHTML = totalResults;
EOF
@@ -14,2 +14,9 @@

function encodeHTML(str) {
return str.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
}

@@ -47,3 +54,3 @@
document.getElementById('search-params').innerHTML = encodeHTML(urlParams.get('query'));
document.getElementById("search-keyword").innerHTML = urlParams.get("query");
document.getElementById("search-keyword").innerHTML = encodeHTML(urlParams.get("query"));
document.getElementById("results-count").innerHTML = totalResults;
Copilot is powered by AI and may make mistakes. Always verify output.

pagerLinks += '<div class="usa-footer__contact-info grid-row grid-gap"><div class="grid-col-auto"><p class="margin-top-0">Powered by <strong>Search.gov</strong></p></div></div>';

pager.innerHTML = pagerLinks;

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.

Copilot Autofix

AI 5 months ago

To fix the issue, we need to sanitize or encode any user-controlled input before inserting it into the DOM. Specifically:

  1. Use the encodeHTML function to sanitize the page variable and any other user-controlled data before appending it to pagerLinks.
  2. Ensure that all dynamic content added to pagerLinks is properly encoded to prevent XSS.

The changes will involve:

  • Applying encodeHTML to the page variable and other user-controlled data in the update_pager function.
  • Ensuring that all HTML content constructed in pagerLinks is safe.
Suggested changeset 1
search/index.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/search/index.html b/search/index.html
--- a/search/index.html
+++ b/search/index.html
@@ -115,6 +115,6 @@
 		for (var i = start; i < page; i++) {
-			pagerLinks += '<a href="' + getLinkToPage(i) + '" aria-label="Page ' + i + '" class="pager-button">' + i + '</a>';
+			pagerLinks += '<a href="' + encodeHTML(getLinkToPage(i)) + '" aria-label="Page ' + encodeHTML(i.toString()) + '" class="pager-button">' + encodeHTML(i.toString()) + '</a>';
 		}
 
-		pagerLinks += '<span class="margin-2, pager-button-current">Page ' + page + " of " + totalPages + "</span>";
+		pagerLinks += '<span class="margin-2, pager-button-current">Page ' + encodeHTML(page.toString()) + " of " + encodeHTML(totalPages.toString()) + "</span>";
         
@@ -122,3 +122,3 @@
 		for (var j = (1*page) + 1; j <= end; j++) {
-			pagerLinks += '<a href="' + getLinkToPage(j) + '" aria-label="Page ' + j + '" class="pager-button">' + j + '</a>';
+			pagerLinks += '<a href="' + encodeHTML(getLinkToPage(j)) + '" aria-label="Page ' + encodeHTML(j.toString()) + '" class="pager-button">' + encodeHTML(j.toString()) + '</a>';
 		}
@@ -130,3 +130,3 @@
         if( totalPages > 1 && page < totalPages){
-            pagerLinks += '<a href="' + getLinkToPage(totalPages) + '" aria-label="Last page" class="pager-button">Last</a>';
+            pagerLinks += '<a href="' + encodeHTML(getLinkToPage(totalPages)) + '" aria-label="Last page" class="pager-button">Last</a>';
         }		
EOF
@@ -115,6 +115,6 @@
for (var i = start; i < page; i++) {
pagerLinks += '<a href="' + getLinkToPage(i) + '" aria-label="Page ' + i + '" class="pager-button">' + i + '</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(i)) + '" aria-label="Page ' + encodeHTML(i.toString()) + '" class="pager-button">' + encodeHTML(i.toString()) + '</a>';
}

pagerLinks += '<span class="margin-2, pager-button-current">Page ' + page + " of " + totalPages + "</span>";
pagerLinks += '<span class="margin-2, pager-button-current">Page ' + encodeHTML(page.toString()) + " of " + encodeHTML(totalPages.toString()) + "</span>";

@@ -122,3 +122,3 @@
for (var j = (1*page) + 1; j <= end; j++) {
pagerLinks += '<a href="' + getLinkToPage(j) + '" aria-label="Page ' + j + '" class="pager-button">' + j + '</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(j)) + '" aria-label="Page ' + encodeHTML(j.toString()) + '" class="pager-button">' + encodeHTML(j.toString()) + '</a>';
}
@@ -130,3 +130,3 @@
if( totalPages > 1 && page < totalPages){
pagerLinks += '<a href="' + getLinkToPage(totalPages) + '" aria-label="Last page" class="pager-button">Last</a>';
pagerLinks += '<a href="' + encodeHTML(getLinkToPage(totalPages)) + '" aria-label="Last page" class="pager-button">Last</a>';
}
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.

4 participants