-
-
Notifications
You must be signed in to change notification settings - Fork 107
Description
As of this statement in #7:
I haven't checked, but are the current CVEs resolved on the fork?
They are related to XSS flaws:
- CVE-2019-11002(
tooltip
component)- CVE-2019-11003(
autocomplete
component)- CVE-2019-11004(
toast
component)
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 of htmlspecialchars()
in PHP. There are plenty examples about this on the internet, the best one I found is this one here:
function escapeHtml(text) {
var map = {'&': '&', '<': '<', '>': '>', '"': '"', "'": '''};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}
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 to false
.
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 to true
.
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 as false
. 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.