Skip to content

GHSA-65cv-r6x7-79hv CVE-2020-5267

Cross site scripting vulnerability in ActionView

Medium RubyGems
Severity
4.8 / 10
Medium · CVSS 3.1
Exploit chance (EPSS)
1.52%
Chance of exploitation in the next 30 days. Higher than 74.67% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-80 Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)
Fix
5.2.4.2
Upgrade actionview to this version or later

Description

There is a possible cross site scripting (XSS) vulnerability in ActionView's JavaScript literal escape helpers. Views that use the j or escape_javascript methods may be susceptible to XSS attacks.

Impact

There is a possible XSS vulnerability in the j and escape_javascript methods in ActionView. These methods are used for escaping JavaScript string literals. Impacted code will look something like this:

<script>let a = `<%= j unknown_input %>`</script>

or

<script>let a = `<%= escape_javascript unknown_input %>`</script>

Releases

The 6.0.2.2 and 5.2.4.2 releases are available at the normal locations.

Workarounds

For those that can't upgrade, the following monkey patch may be used:

ActionView::Helpers::JavaScriptHelper::JS_ESCAPE_MAP.merge!(
  {
    "`" => "\\`",
    "$" => "\\$"
  }
)

module ActionView::Helpers::JavaScriptHelper
  alias :old_ej :escape_javascript
  alias :old_j :j

  def escape_javascript(javascript)
    javascript = javascript.to_s
    if javascript.empty?
      result = ""
    else
      result = javascript.gsub(/(\\|<\/|\r\n|\342\200\250|\342\200\251|[\n\r"']|[`]|[$])/u, JS_ESCAPE_MAP)
    end
    javascript.html_safe? ? result.html_safe : result
  end

  alias :j :escape_javascript
end

Patches

To aid users who aren't able to upgrade immediately we have provided patches for the two supported release series. They are in git-am format and consist of a single changeset.

Please note that only the 5.2 and 6.0 series are supported at present. Users of earlier unsupported releases are advised to upgrade as soon as possible as we cannot guarantee the continued availability of security fixes for unsupported releases.

Credits

Thanks to Jesse Campos from Chef Secure

Affected versions

RubyGems

PackageVulnerableFixed in
actionview
< 5.2.4.2
5.2.4.2
actionview
>= 6.0.0, < 6.0.2.2
6.0.2.2

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

actionview RubyGems → 5.2.4.2

bundler
bundle update actionview # Gemfile: gem "actionview", ">= 5.2.4.2"

Severity breakdown

CVSS 3.1 4.8

CVSS:3.1/AV:N/AC:L/PR:H/UI:R/S:C/C:L/I:L/A:N

Attack vector
Network
Attack complexity
Low
Privileges required
High
User interaction
Required
Scope
Changed
Confidentiality
Low
Integrity
Low
Availability
None

Weakness

CWE-80: Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)

The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special characters such as "<", ">", and "&" that could be interpreted as web-scripting elements when they are sent to a downstream component that processes web pages.

How to prevent it
  • Implementation: Carefully check each input parameter against a rigorous positive specification (allowlist) defining the specific characters and format allowed. All input should be neutralized, not just parameters that the user is supposed to specify, but all data in the request, including hidden fields, cookies, headers, the URL itself, and so forth. A common mistake that leads to continuing XSS vulnerabilities is to validate only fields that are expected to be redisplayed by the site. We often encounter data from the request that is reflected by the application server or the application that the development team did not anticipate. Also, a field that is not currently reflected may be used by a future developer. Therefore, validating ALL parts of the HTTP request is recommended.
  • Implementation: Use and specify an output encoding that can be handled by the downstream component that is reading the output. Common encodings include ISO-8859-1, UTF-7, and UTF-8. When an encoding is not specified, a downstream component may choose a different encoding, either by assuming a default encoding or automatically inferring which encoding is being used, which can be erroneous. When the encodings are inconsistent, the downstream component might treat some character or byte sequences as special, even if they are not special in the original encoding. Attackers might then be able to exploit this discrepancy and conduct injection attacks; they even might be able to bypass protection mechanisms that assume the original encoding is also being used by the downstream component. The problem of inconsistent output encodings often arises in web pages. If an encoding is not specified in an HTTP header, web browsers often guess about which encoding is being used. This can open up the browser to subtle XSS attacks.
  • Implementation: With Struts, write all data from form beans with the bean's filter attribute set to true.
  • Implementation: To help mitigate XSS attacks against the user's session cookie, set the session cookie to be HttpOnly. In browsers that support the HttpOnly feature (such as more recent versions of Internet Explorer and Firefox), this attribute can prevent the user's session cookie from being accessible to malicious client-side scripts that use document.cookie. This is not a complete solution, since HttpOnly is not supported by all browsers. More importantly, XmlHttpRequest and other powerful browser technologies provide read access to HTTP headers, including the Set-Cookie header in which the HttpOnly flag is set.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
CVE-2019-5418
Path Traversal in Action View
High Known exploited Also affects actionview
GHSA-xrr4-p6fq-hjg7
Directory traversal vulnerability in Action View in Ruby on Rails
High Known exploited Also affects actionview
GHSA-v55j-83pf-r9cq
Rails has a possible XSS vulnerability in its Action View tag helpers
Low Also affects actionview
GHSA-xp5h-f8jf-rc8q
rails-ujs vulnerable to DOM Based Cross-site Scripting contenteditable HTML Elements
Medium Also affects actionview
GHSA-ch3h-j2vf-95pv
XSS Vulnerability in Action View tag helpers
Medium Also affects actionview
GHSA-cfjv-5498-mph5
XSS in Action View
Medium Also affects actionview
GHSA-cr3x-7m39-c6jq
Remote code execution via user-provided local names in ActionView
High Also affects actionview
GHSA-xq5j-gw7f-jgj8
CSRF Vulnerability in rails-ujs
Medium Also affects actionview
Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor