CVE-2021-42576: Cross-site scripting in github.com/microcosm-cc/bluemonday

Summary

15/08/2022
Yes i
Unrated
Not published

CVE-2021-42576: Cross-site scripting via leaked style elements in github.com/microcosm-cc/bluemonday. Affects github.com/microcosm-cc/bluemonday versions < 1.0.16. Fixed in 1.0.16. How to fix ↓

Also tracked for

The same CVE-2021-42576 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The package under scrutiny is github.com/microcosm-cc/bluemonday, which is an HTML sanitizer for Go. It is used to sanitize user-generated HTML content to prevent cross-site scripting (XSS) attacks. The package provides various sanitization policies to allow or disallow specific HTML elements and attributes. However, user-defined policies allowing 'select', 'style', and 'option' elements are vulnerable to a cross-site scripting vulnerability.

Vulnerability Detail

The bluemonday HTML sanitizer can leak the contents of a 'style' element into HTML output, potentially causing XSS vulnerabilities. This vulnerability affects user-defined policies that permit the 'style' element. It is important to note that the default bluemonday sanitization policies are not vulnerable. The package does not contain a CSS sanitizer, making permitting the 'style' element in policies hazardous. Newer versions of bluemonday suppress 'style' and 'script' elements even when allowed by a policy unless the policy explicitly requests unsafe processing.

How To Fix

Minimum fixed version

1.0.16

This is the first release that contains the fix.

go get github.com/microcosm-cc/bluemonday@v1.0.16

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If updating the package is not immediately possible, a temporary workaround is to avoid allowing the 'style' element in user-defined policies. By disallowing the 'style' element, the risk of XSS vulnerabilities can be mitigated. Here is an example of how to disallow the 'style' element using the bluemonday package:

github.com/microcosm-cc/bluemonday.Policy.AllowElements([]string{"select", "option"})

Conclusion

In conclusion, the github.com/microcosm-cc/bluemonday package is vulnerable to a cross-site scripting (XSS) vulnerability when user-defined policies allow the 'style' element. To fix this vulnerability, it is crucial to update the package to version 1.0.16 or later. If immediate updating is not possible, disallowing the 'style' element in user-defined policies can serve as a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for github.com/microcosm-cc/bluemonday →

Share this vulnerability

FAQ

Bluemonday is an HTML sanitizer package for Go. It is used to sanitize user-generated HTML content and prevent cross-site scripting (XSS) attacks.

Versions prior to 1.0.16 are affected by this vulnerability. It is recommended to update to version 1.0.16 or later to fix the issue.

No, the default bluemonday sanitization policies are not vulnerable to this XSS vulnerability. Only user-defined policies allowing the 'select', 'style', and 'option' elements are affected.

No, bluemonday does not contain a CSS sanitizer. Permitting the 'style' element in policies is hazardous as it can lead to XSS vulnerabilities.

To mitigate the risk of XSS vulnerabilities, it is recommended to update the bluemonday package to version 1.0.16 or later. Additionally, avoid allowing the 'style' element in user-defined policies.

Related vulnerabilities

Recent vulnerabilities recorded for github.com/microcosm-cc/bluemonday.

How To Fix

Minimum fixed version

1.0.16

This is the first release that contains the fix.

go get github.com/microcosm-cc/bluemonday@v1.0.16

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback