CVE-2018-3740: Sanitize Cross-Site Scripting Vulnerability

HIGH
Advisory Identifier: GHSA-7f42-p84j-f58p
CVSS 7.5
CWE-20 CWE-79
Published
Advisory Summary

CVE-2018-3740 is a HIGH (CVSS 7.5) cross-site scripting vulnerability (CWE-20: Improper Input Validation) affecting Sanitize libraries in the RubyGems ecosystem. The issue involves sanitize vulnerable to improper input validation and cross-site scripting. Remediation is available by upgrading affected packages to version 4.6.3.

CVE-2018-3740 at a Glance

CVE Identifier CVE-2018-3740
GHSA Identifier GHSA-7f42-p84j-f58p
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-20: Improper Input Validation
Affected Product Sanitize
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2018-3740

To remediate this vulnerability, upgrade all affected Sanitize dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

sanitize fixed: 4.6.3
Upgrade sanitize to 4.6.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for sanitize

How to Check if You Are Affected

To determine whether your application is affected by CVE-2018-3740, inspect your project dependencies for Sanitize:

inspect dependencies for sanitize

Analyze the terminal output to locate any version of Sanitize in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.6.3), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-20: Improper Input Validation, where the product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly. In Sanitize, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

When Sanitize <= 4.6.2 is used in combination with libxml2 >= 2.9.2, a specially crafted HTML fragment can cause libxml2 to generate improperly escaped output, allowing non-whitelisted attributes to be used on whitelisted elements. This can allow HTML and JavaScript injection, which could result in XSS if Sanitize's output is served to browsers.

CVE-2018-3740 Affected Sanitize Versions

1 component(s)
Fixed Versions:
4.6.3
Product / Package Ecosystem Affected Versions Fixed Version
sanitize
RubyGems
≥ 3.0.0
< 4.6.3
4.6.3

References

Frequently Asked Questions

What is CVE-2018-3740?
CVE-2018-3740 is a security vulnerability in Sanitize involving Sanitize vulnerable to Improper Input Validation and Cross-site Scripting under CWE-20: Improper Input Validation.
Which Sanitize versions are affected?
Affected versions include releases prior to 4.6.3 across affected packages: sanitize.
What version fixes CVE-2018-3740?
Upgrading to 4.6.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is sanitize affected?
Yes, sanitize is affected in releases prior to 4.6.3. Upgrade your dependency to 4.6.3 or later.
What is the CVSS score of CVE-2018-3740?
CVE-2018-3740 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2018-3740?
CVE-2018-3740 is classified under CWE-20: Improper Input Validation (The product receives input or data, but it does not validate or incorrectly validates that the input has the properties that are required to process the data safely and correctly.).
How can I check RubyGems dependencies for CVE-2018-3740?
Run the dependency tree command: 'inspect dependencies for sanitize'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-7f42-p84j-f58p",
  "modified" : "2023-01-23T20:47:11Z",
  "published" : "2018-03-21T11:56:32Z",
  "aliases" : [ "CVE-2018-3740" ],
  "summary" : "Sanitize vulnerable to Improper Input Validation and Cross-site Scripting",
  "details" : "When Sanitize <= 4.6.2 is used in combination with libxml2 >= 2.9.2, a specially crafted HTML fragment can cause libxml2 to generate improperly escaped output, allowing non-whitelisted attributes to be used on whitelisted elements.\n\nThis can allow HTML and JavaScript injection, which could result in XSS if Sanitize's output is served to browsers.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "sanitize"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "4.6.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2018-3740"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rgrove/sanitize/issues/176"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rgrove/sanitize/commit/01629a162e448a83d901456d0ba8b65f3b03d46e"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rgrove/sanitize/commit/93feeb38e21864146bb29191792b971dbe1ec62e"
  }, {
    "type" : "WEB",
    "url" : "https://about.gitlab.com/2018/06/25/security-release-gitlab-11-dot-0-dot-1-released"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/rgrove/sanitize"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/sanitize/CVE-2018-3740.yml"
  }, {
    "type" : "WEB",
    "url" : "https://www.debian.org/security/2018/dsa-4358"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-20", "CWE-79" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-06-16T21:22:33Z",
    "nvd_published_at" : "2018-03-30T19:29:00Z"
  }
}