56437 - #2
Conversation
| options[attr] = exoptions[attr]; | ||
| } | ||
| } | ||
| debug('Http request: %j', options); |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to ensure that sensitive information such as passwords is not logged. The best way to fix this is to sanitize the options object before logging it. We can create a copy of the options object and remove or mask any sensitive information before passing it to the debug function.
- Create a sanitized copy of the
optionsobject. - Remove or mask sensitive information such as passwords from the sanitized copy.
- Log the sanitized copy instead of the original
optionsobject.
| @@ -159,3 +159,7 @@ | ||
| } | ||
| debug('Http request: %j', options); | ||
| const sanitizedOptions = { ...options }; | ||
| if (sanitizedOptions.headers && sanitizedOptions.headers.Authorization) { | ||
| sanitizedOptions.headers.Authorization = '***'; | ||
| } | ||
| debug('Http request: %j', sanitizedOptions); | ||
| return options; |
| if (typeof body === 'string') { | ||
| // Remove any extra characters that appear before or after the SOAP envelope. | ||
| const regex = /(?:<\?[^?]*\?>[\s]*)?<([^:]*):Envelope([\S\s]*)<\/\1:Envelope>/i; | ||
| const match = body.replace(/<!--[\s\S]*?-->/, '').match(regex); |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
| if (typeof body === 'string') { | ||
| // Remove any extra characters that appear before or after the SOAP envelope. | ||
| const regex = /(?:<\?[^?]*\?>[\s]*)?<([^:]*):Envelope([\S\s]*)<\/\1:Envelope>/i; | ||
| const match = body.replace(/<!--[\s\S]*?-->/, '').match(regex); |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
| if (typeof body === 'string') { | ||
| // Remove any extra characters that appear before or after the SOAP envelope. | ||
| const regex = /(?:<\?[^?]*\?>[\s]*)?<([^:]*):Envelope([\S\s]*)<\/\1:Envelope>/i; | ||
| const match = body.replace(/<!--[\s\S]*?-->/, '').match(regex); |
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to ensure that all occurrences of HTML comments are removed from the body string. The best way to achieve this is to apply the regular expression replacement repeatedly until no more replacements can be performed. This ensures that all instances of the targeted pattern are removed.
We will modify the handleResponse method to repeatedly apply the regular expression replacement until the body string no longer changes. This approach guarantees that all HTML comments are removed, preventing any potential injection vulnerabilities.
| @@ -175,3 +175,8 @@ | ||
| const regex = /(?:<\?[^?]*\?>[\s]*)?<([^:]*):Envelope([\S\s]*)<\/\1:Envelope>/i; | ||
| const match = body.replace(/<!--[\s\S]*?-->/, '').match(regex); | ||
| let previous; | ||
| do { | ||
| previous = body; | ||
| body = body.replace(/<!--[\s\S]*?-->/g, ''); | ||
| } while (body !== previous); | ||
| const match = body.match(regex); | ||
| if (match) { |
| const endOfSecurityHeader = xml.indexOf('</wsse:Security>'); | ||
| if (endOfSecurityHeader > -1) { | ||
| const securityHeaderRegexp = /<wsse:Security( [^>]*)?>/; | ||
| const match = xml.match(securityHeaderRegexp); |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data
| if (~ns.indexOf('http://www.w3.org/')) { | ||
| continue; | ||
| } | ||
| if (~ns.indexOf('http://xml.apache.org/')) { |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the problem, we need to replace the substring check with a more robust method that parses the URL and verifies the host explicitly. This involves using the url module to parse the URL and then checking the host against a whitelist of allowed hosts.
- Parse the URL using the
urlmodule to extract the host. - Check if the host is in a predefined list of allowed hosts.
- Replace the substring check with this new method.
| @@ -1346,3 +1346,5 @@ | ||
| } | ||
| if (~ns.indexOf('http://xml.apache.org/')) { | ||
| const parsedUrl = url.parse(ns); | ||
| const allowedHosts = ['xml.apache.org']; | ||
| if (allowedHosts.includes(parsedUrl.host)) { | ||
| continue; |
| before(function (done) { | ||
| // start test soap server (hello.wsdl) | ||
| server = http.createServer(function (request, response) { | ||
| response.end('404: Not Found: ' + request.url); |
Check failure
Code scanning / CodeQL
Reflected cross-site scripting
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the reflected cross-site scripting vulnerability, we need to sanitize the user input before including it in the HTTP response. The best way to do this is by using a library that provides HTML escaping functionality. This will ensure that any potentially malicious characters in the user input are properly encoded, preventing the execution of scripts.
In this case, we can use the escape-html library to sanitize the request.url before including it in the response. This change will be made in the test/client-response-options-test.js file.
| @@ -5,3 +5,4 @@ | ||
| http = require('http'), | ||
| assert = require('assert'); | ||
| assert = require('assert'), | ||
| escapeHtml = require('escape-html'); | ||
|
|
||
| @@ -28,3 +29,3 @@ | ||
| server = http.createServer(function (request, response) { | ||
| response.end('404: Not Found: ' + request.url); | ||
| response.end('404: Not Found: ' + escapeHtml(request.url)); | ||
| }); |
| @@ -18,3 +18,4 @@ | ||
| "whatwg-mimetype": "4.0.0", | ||
| "xml-crypto": "^6.0.1" | ||
| "xml-crypto": "^6.0.1", | ||
| "escape-html": "^1.0.3" | ||
| }, |
| Package | Version | Security advisories |
| escape-html (npm) | 1.0.3 | None |
| before(function (done) { | ||
|
|
||
| server = http.createServer(function(request,response) { | ||
| response.end('404: Not Found: ' + request.url); |
Check failure
Code scanning / CodeQL
Reflected cross-site scripting
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the reflected cross-site scripting vulnerability, we need to sanitize the request.url before including it in the response. The best way to do this is by using a well-known library for escaping HTML, such as escape-html. This will ensure that any potentially malicious content in the URL is properly escaped and cannot be executed as a script in the user's browser.
We will:
- Import the
escape-htmllibrary. - Use the
escapefunction from theescape-htmllibrary to sanitize therequest.urlbefore including it in the response.
| @@ -1,8 +1,9 @@ | ||
| 'use strict'; | ||
|
|
||
| var assert = require('assert'); | ||
| var http = require('http'); | ||
| var soap = require('..'); | ||
| var server; | ||
| var url; | ||
| 'use strict'; | ||
|
|
||
| var assert = require('assert'); | ||
| var http = require('http'); | ||
| var escape = require('escape-html'); | ||
| var soap = require('..'); | ||
| var server; | ||
| var url; | ||
|
|
||
| @@ -77,5 +78,5 @@ | ||
|
|
||
| server = http.createServer(function(request,response) { | ||
| response.end('404: Not Found: ' + request.url); | ||
| }); | ||
| server = http.createServer(function(request,response) { | ||
| response.end('404: Not Found: ' + escape(request.url)); | ||
| }); | ||
|
|
| @@ -18,3 +18,4 @@ | ||
| "whatwg-mimetype": "4.0.0", | ||
| "xml-crypto": "^6.0.1" | ||
| "xml-crypto": "^6.0.1", | ||
| "escape-html": "^1.0.3" | ||
| }, |
| Package | Version | Security advisories |
| escape-html (npm) | 1.0.3 | None |
|
|
||
|
|
||
| server = http.createServer(function (request, response) { | ||
| response.end('404: Not Found: ' + request.url); |
Check failure
Code scanning / CodeQL
Reflected cross-site scripting
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the reflected cross-site scripting vulnerability, we need to sanitize the user input before including it in the HTTP response. The best way to do this is by using a library that provides HTML escaping functionality. This will ensure that any potentially malicious characters in the request.url are properly encoded, preventing the execution of scripts.
We will use the escape-html library to sanitize the request.url before including it in the response. This involves:
- Installing the
escape-htmllibrary. - Importing the
escape-htmllibrary in the file. - Using the
escapefunction from theescape-htmllibrary to sanitize therequest.url.
| @@ -6,2 +6,3 @@ | ||
| const { default: axios } = require('axios'); | ||
| var escape = require('escape-html'); | ||
| var server; | ||
| @@ -54,3 +55,3 @@ | ||
| server = http.createServer(function (request, response) { | ||
| response.end('404: Not Found: ' + request.url); | ||
| response.end('404: Not Found: ' + escape(request.url)); | ||
| }); |
| @@ -18,3 +18,4 @@ | ||
| "whatwg-mimetype": "4.0.0", | ||
| "xml-crypto": "^6.0.1" | ||
| "xml-crypto": "^6.0.1", | ||
| "escape-html": "^1.0.3" | ||
| }, |
| Package | Version | Security advisories |
| escape-html (npm) | 1.0.3 | None |
| before(function (done) { | ||
|
|
||
| server = http.createServer(function (request, response) { | ||
| response.end('404: Not Found: ' + request.url); |
Check failure
Code scanning / CodeQL
Reflected cross-site scripting
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI over 1 year ago
To fix the reflected cross-site scripting vulnerability, we need to sanitize the user input before incorporating it into the response. The best way to do this is by using a library that provides HTML escaping functionality. In this case, we can use the escape-html library to escape the request.url before including it in the response.
- Install the
escape-htmllibrary. - Import the
escape-htmllibrary in the file. - Use the
escapefunction from theescape-htmllibrary to sanitize therequest.urlbefore concatenating it into the response.
| @@ -7,2 +7,3 @@ | ||
| const { default: axios } = require('axios'); | ||
| var escape = require('escape-html'); | ||
| var server; | ||
| @@ -43,3 +44,3 @@ | ||
| server = http.createServer(function (request, response) { | ||
| response.end('404: Not Found: ' + request.url); | ||
| response.end('404: Not Found: ' + escape(request.url)); | ||
| }); |
| @@ -18,3 +18,4 @@ | ||
| "whatwg-mimetype": "4.0.0", | ||
| "xml-crypto": "^6.0.1" | ||
| "xml-crypto": "^6.0.1", | ||
| "escape-html": "^1.0.3" | ||
| }, |
| Package | Version | Security advisories |
| escape-html (npm) | 1.0.3 | None |
611fca9 to
9c6ad01
Compare
No description provided.