CVE-2020-5217: Secure headers Directive Injection When Using Dynamic Vulnerability

MODERATE
Advisory Identifier: GHSA-xq52-rv6w-397c
CVSS 4.4
CWE-95
Published
Advisory Summary

CVE-2020-5217 is a MODERATE (CVSS 4.4) directive injection when using dynamic vulnerability (CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')) affecting Secure headers libraries in the RubyGems ecosystem. The issue involves directive injection when using dynamic overrides with user input. Remediation is available by upgrading affected packages to version 6.2.0, 5.1.0, 3.8.0.

CVE-2020-5217 at a Glance

CVE Identifier CVE-2020-5217
GHSA Identifier GHSA-xq52-rv6w-397c
Severity MODERATE
CVSS v3.1 Base Score 4.4
CWE Classification CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')
Affected Product Secure headers
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 4.4

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

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

How to Fix CVE-2020-5217

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

secure_headers fixed: 6.2.0
Upgrade secure_headers to 6.2.0
secure_headers fixed: 5.1.0
Upgrade secure_headers to 5.1.0
secure_headers fixed: 3.8.0
Upgrade secure_headers to 3.8.0
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 secure_headers

How to Check if You Are Affected

To determine whether your application is affected by CVE-2020-5217, inspect your project dependencies for Secure headers:

inspect dependencies for secure_headers

Analyze the terminal output to locate any version of Secure headers in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.2.0), 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-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection'), where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before using the input in a dynamic evaluation call (e.g. "eval"). In Secure headers, 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

### Impact If user-supplied input was passed into `append/override_content_security_policy_directives`, a semicolon could be injected leading to directive injection. This could be used to e.g. override a `script-src` directive. Duplicate directives are ignored and the first one wins. The directives in `secure_headers` are sorted alphabetically so they pretty much all come before `script-src`. A previously undefined directive would receive a value even if `SecureHeaders::OPT_OUT` was supplied. The fixed versions will silently convert the semicolons to spaces and emit a deprecation warning when this happens. This will result in innocuous browser console messages if being exploited/accidentally used. In future releases, we will raise application errors resulting in 500s. > Duplicate script-src directives detected. All but the first instance will be ignored. See https://www.w3.org/TR/CSP3/#parse-serialized-policy > Note: In this case, the user agent SHOULD notify developers that a duplicate directive was ignored. A console warning might be appropriate, for example. ### Patches Depending on what major version you are using, the fixed versions are 6.2.0, 5.1.0, 3.8.0. ### Workarounds If you are passing user input into the above methods, you could filter out the input: ```ruby override_content_security_policy_directives(:frame_src, [user_input.gsub(";", " ")]) ``` ### References Reported in https://github.com/twitter/secure_headers/issues/418 https://www.w3.org/TR/CSP3/#parse-serialized-policy ### For more information If you have any questions or comments about this advisory: * Open an issue in [this repo](https://github.com/twitter/secure_headers/issues/new) * DM @ndm on twitter

CVE-2020-5217 Affected Secure headers Versions

3 component(s)
Fixed Versions:
6.2.05.1.03.8.0
Product / Package Ecosystem Affected Versions Fixed Version
secure_headers
RubyGems
≥ 6.0.0
< 6.2.0
6.2.0
secure_headers
RubyGems
≥ 5.0.0
< 5.1.0
5.1.0
secure_headers
RubyGems
< 3.8.0
3.8.0

References

Frequently Asked Questions

What is CVE-2020-5217?
CVE-2020-5217 is a security vulnerability in Secure headers involving Directive injection when using dynamic overrides with user input under CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection').
Which Secure headers versions are affected?
Affected versions include releases prior to 6.2.0, 5.1.0, 3.8.0 across affected packages: secure_headers.
What version fixes CVE-2020-5217?
Upgrading to 6.2.0, 5.1.0, 3.8.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is secure_headers affected?
Yes, secure_headers is affected in releases prior to 6.2.0, 5.1.0, 3.8.0. Upgrade your dependency to 6.2.0, 5.1.0, 3.8.0 or later.
What is the CVSS score of CVE-2020-5217?
CVE-2020-5217 has a CVSS v3.1 base score of 4.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2020-5217?
CVE-2020-5217 is classified under CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection') (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before using the input in a dynamic evaluation call (e.g. "eval").).
How can I check RubyGems dependencies for CVE-2020-5217?
Run the dependency tree command: 'inspect dependencies for secure_headers'. 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-xq52-rv6w-397c",
  "modified" : "2023-05-16T16:09:56Z",
  "published" : "2020-01-23T02:28:11Z",
  "aliases" : [ "CVE-2020-5217" ],
  "summary" : "Directive injection when using dynamic overrides with user input",
  "details" : "### Impact\n\nIf user-supplied input was passed into `append/override_content_security_policy_directives`, a semicolon could be injected leading to directive injection.\n\nThis could be used to e.g. override a `script-src` directive. Duplicate directives are ignored and the first one wins. The directives in `secure_headers` are sorted alphabetically so they pretty much all come before `script-src`. A previously undefined directive would receive a value even if `SecureHeaders::OPT_OUT` was supplied.\n\nThe fixed versions will silently convert the semicolons to spaces and emit a deprecation warning when this happens. This will result in innocuous browser console messages if being exploited/accidentally used. In future releases, we will raise application errors resulting in 500s.\n\n> Duplicate script-src directives detected.  All but the first instance will be ignored.\n\nSee https://www.w3.org/TR/CSP3/#parse-serialized-policy\n\n> Note: In this case, the user agent SHOULD notify developers that a duplicate directive was ignored. A console warning might be appropriate, for example.\n\n### Patches\n\nDepending on what major version you are using, the fixed versions are 6.2.0, 5.1.0, 3.8.0.\n\n### Workarounds\n\nIf you are passing user input into the above methods, you could filter out the input:\n\n```ruby\noverride_content_security_policy_directives(:frame_src, [user_input.gsub(\";\", \" \")])\n```\n\n### References\n\nReported in https://github.com/twitter/secure_headers/issues/418\nhttps://www.w3.org/TR/CSP3/#parse-serialized-policy\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n* Open an issue in [this repo](https://github.com/twitter/secure_headers/issues/new)\n* DM @ndm on twitter ",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "secure_headers"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "6.0.0"
      }, {
        "fixed" : "6.2.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "secure_headers"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0"
      }, {
        "fixed" : "5.1.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "secure_headers"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.8.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/twitter/secure_headers/security/advisories/GHSA-xq52-rv6w-397c"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2020-5217"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twitter/secure_headers/issues/418"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twitter/secure_headers/pull/421"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/twitter/secure_headers/commit/936a160e3e9659737a9f9eafce13eea36b5c9fa3"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/secure_headers/CVE-2020-5217.yml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/twitter/secure_headers"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-95" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2020-01-23T02:12:03Z",
    "nvd_published_at" : null
  }
}