-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Plan to fix all current CVEs #38
Comments
I would suggest DOMPurify which is also used by others and Bootstrap mentions it at https://getbootstrap.com/docs/4.3/getting-started/javascript/. I would not write our own sanitizer / reinvent the wheel as this could also lead to other issues like bypasses due to problems in the logic. |
As long as it doesn't introduce too much overhead/bloat on the dependencies, I feel like it's okay to introduce a new dependency for this 👍 |
You only need sanitizers if you want to allow HTML. Currently autocomplete does not work and is not indended to work with HTML data. So autocomplete wouldn't need sanitizer, it would simply need to use
I just want to emphasise that this does not fix the vulnerability with autocomplete, as demonstrated here. If you don't sanitize the data, Root of the problem is Autocomplete._highlight first calling |
@Pierstoval I've been reading through the other discussions on this, including the response from Snyk, and I like the suggestion from @lirantal for Toast. It would be easy (I assume) and non-breaking to add a properly sanitized @DanielRuf I think this is worth a slightly breaking change on Autocomplete for the first release of materializecss/materialize for the following reasons:
Thoughts? I think the change can be minimally breaking by adding a default property to the Autocomplete options like |
Yes thats awesome! It would also be very cool to add IDs to the Autocomplete Data. |
In't the code here also a problem? materialize/js/autocomplete.js Lines 382 to 386 in a8a30a3
The image URL could potentially be a user-supplied avatar URL. Is the escaping done by the following sufficient? img = document.createElement('img');
document.body.appendChild(img);
img.src="x\" onerror=\"alert(\'XSS Attack\')\"";
console.log(img.src);
// Output: "x%22%20onerror=%22alert('XSS%20Attack')%22" |
As of this statement in #7:
We know the CVEs are not fixed yet on Materialize, and there are already discussions in the original repository (Dogfalo#6331 and Dogfalo#6286) about this subject.
Current situation
Since the current CVEs are related to XSS that can be triggered when Materialize is used in a bad manner, this is the developer's responsibility to sanitize their data before using the three aforementioned components.
However, since the warnings will still display, and since Materialize can be "considered harmful" because of these (even though the discussions on the original repo suggest that it's not Materialize's problem, but rather how devs are using it), we should still find solutions to fix the warnings in an easy and backwards-compatible manner.
This is important for some CI that don't accept dependencies with warnings, or for clients that are worried about warnings they might not understand, especially when it's written "XSS" in them (which is a well-known flaw on the web in general)
Proposal
I suggest that for all the three involved components we add a boolean
sanitizeInput
option.When this option is
true
, the input data will be sanitized with an equivalent ofhtmlspecialchars()
in PHP. There are plenty examples about this on the internet, the best one I found is this one here:Suggestions on other sanitizing methods are encouraged, since this has never been a "standard" process in the web industry 😄 .
Behavior on Materialize 1.x
This option will by default be
null
. To keep backwards compatibility,null
will be equivalent tofalse
.However, if we detect
null
, we display a warning in the console, as a reminder to the developer that the native behavior of not-sanitizing is deprecated, and default value will change in 2.x totrue
.To remove the warning, we suggest the user to specify the value themselves, even if it's
false
.An explicit
false
will not trigger the warning, since this means that the developer knows what they are doing, and in such case, Materialize cannot guarantee input data safety.Behavior on the future Materialize 2.x branch
Here, default value is
true
, and any falsy value will be interpreted asfalse
. We could add type checks to force the user to specify a boolean, but I think this might be overkill. Suggestions appreciated 😉Feel free to discuss all the different points, and even provide PRs if necessary.
The text was updated successfully, but these errors were encountered: