Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPP-5370][Update XSS Vulnerabilities] #5758

Open
wants to merge 5 commits into
base: XSS-PPP-5370
Choose a base branch
from

Conversation

mmujahiduddin
Copy link

Update XSS Vulnerabilities

@mmujahiduddin mmujahiduddin requested a review from a team as a code owner October 30, 2024 11:18
@buildguy

This comment has been minimized.

@buildguy
Copy link
Collaborator

👍 Frogbot scanned this pull request and did not find any new security issues.

Note:

Frogbot also supports Contextual Analysis, Secret Detection, IaC and SAST Vulnerabilities Scanning. This features are included as part of the JFrog Advanced Security package, which isn't enabled on your system.


@buildguy

This comment has been minimized.

assemblies/pentaho-war/src/main/webapp/js/ajaxslt/dom.js Outdated Show resolved Hide resolved
@@ -10,6 +10,9 @@
* Change Date: 2028-08-13
******************************************************************************/

define(['common-ui/util/xss'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, this file is not referenced anywhere.

It appears to demonstrate use of some Google Maps component (GeoCoder) via Pentaho XActions. XActions are essentially deprecated.

Unless you can find a reference to it, solving the XSS issue by removing the file.

Copy link
Contributor

@dcleao dcleao Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not addressed yet.

@@ -20,11 +23,11 @@ function runInBackground( url, target )
url = url + "&background=true";
if ( target.toLowerCase().indexOf( 'new' ) >= 0 )
{
var targetWin = window.open( url );
var targetWin = window.open(xssUtil.sanitizeHtml(url), 'noopener,noreferrer');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not prepared to be a RequireJS module, and, as such, you should use the global version of the XSS utility library, available under pho.util.xss (and undo the proposed RequireJS modifications).

However, the library does not currently offer any mechanism to validate URLs. AFAIR (but please confirm!), URL protection against XSS consists of ensuring that the URL does not have a javascript protocol. A function such as sanitizeUrl(url) should be added to the XSS utility and then used here.

I am not sure what's the best source to base our implementation of, in this regard. Some pointers:

Copy link
Contributor

@dcleao dcleao Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this, I think we might be able to use DOMPurify to this effect.

In the DOMPlurify playground page, https://cure53.de/purify, try out the following sample Dirty HTML:

<a href='
  javas cript:alert(1)'>I am a dolphin!</a>
<a href='http://www.google.com'>I am a dolphin!</a>

It cleans it as:

<a>I am a dolphin!</a>
<a href="http://www.google.com">I am a dolphin!</a>

As such, we should be able to implement sanitizeUrl(url) by creating a dummy a element string with the URL as the href attribute: '<a href="' + url + '">'. Then reading back the resulting href value, if any.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another aspect which must be considered is whether the suggested sanitizeUrl() method alone would automatically resolve the AppScan finding. I believe the finding is being triggered due to any use of window.open() with a URL string. And so we should need to also create a method such as xssUtil.openWindow(window, url, options) that achieves this in a safe way (by internally sanitizing the URL and hiding the call to window.open).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the new code is already using the new sanitizeUrl method, the above request, to use openWindow instead, was still not addressed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also notice the window.location line, which would need a new XSS Util method to be automatically resolved by App Scan.

It seems that we need another method to achieve that. Something like:

   setWindowLocation: function(url) {
     window.location = xssUtil.sanitizeUrl(url);
   }

assemblies/pentaho-war/src/main/webapp/js/parameters.js Outdated Show resolved Hide resolved
assemblies/pentaho-war/src/main/webapp/js/src/html/util.js Outdated Show resolved Hide resolved
document.getElementById(datePickerDivID).innerHTML = html;

xssUtil.setHtml(document.getElementById(datePickerDivID), html);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not prepared to be a RequireJS module, and, as such, you should use the global version of the XSS utility library, available under pho.util.xss (and undo the proposed RequireJS modifications).

As you can see in the code above, there are multiple instances of event handler attributes (e.g. onMouseOut, onClick), which using setHtml would eliminate altogether, breaking the functionality.
Instead, must sanitize/encode the parts used to build the HTML string which may pose a XSS risk.

The arguments year, month and day are already properly handled in a safe manner.

The argument dateFieldName however is being used directly as a JavaScript string (with quotes, double or single, provided outside). It should be escaped before use. We need a a function such as encodeForJavaScript(text) (following, for example, OWASP's functionality of OWASP Encoder) and add it to the XSS utility and then use here.

Then, in this same line, mark the setting of unsafe HTML using xssUtil.setHtmlUnsafe(document.getElementById(datePickerDivID), html); instead.

Note that method getButtonCode also needs to be changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not addressed yet.

window.open( url );
/* noopener and noreferrer: These attributes mitigate the risk of tabnabbing and
prevent the new page from accessing the original window’s properties. */
window.open(xssUtil.sanitizeHtml(url),'noopener,noreferrer');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not prepared to be a RequireJS module, and, as such, you should use the global version of the XSS utility library, available under pho.util.xss (and undo the proposed RequireJS modifications).

Please, use the new method suggested above, pho.util.xss.sanitizeUrl(..).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, as said elsewhere, please use the proposed new method, pho.util.xss.openWindow in these cases.

window.open(href, "_blank");
/* noopener and noreferrer: These attributes mitigate the risk of tabnabbing and
prevent the new page from accessing the original window’s properties. */
window.open(xssUtil.sanitizeHtml(href), "_blank", 'noopener,noreferrer');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use the new method suggested above, xssUtil.sanitizeUrl(..).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, as said elsewhere, please use the proposed new method, pho.util.xss.openWindow in these cases.

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
36.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

@buildguy
Copy link
Collaborator

buildguy commented Nov 7, 2024

❌ Build failed in 1h 5s

Build command:

mvn clean verify -B -e -Daudit -Djs.no.sandbox

👌 All tests passed!

Tests run: 2724, Failures: 0, Skipped: 5    Test Results


ℹ️ This is an automatic message

@mmujahiduddin mmujahiduddin changed the base branch from BACKLOG-41215 to XSS-PPP-5370 November 11, 2024 08:42
Copy link
Contributor

@dcleao dcleao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from some local requests, this PR requires the following new XSS Utility features to be merged:

  1. openWindow
  2. setWindowLocation
  3. encodeForJavaScript

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