From 16251735e36ebdc302e2f90f2a39cad56879414f Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 30 Nov 2024 16:16:29 -0500 Subject: [PATCH] fix: disallow 'noscript' from safe lists https://hackerone.com/reports/2509647 --- lib/rails/html/scrubbers.rb | 6 ++++++ test/sanitizer_test.rb | 35 +++++++++++++++++++++++++++++++++++ test/scrubbers_test.rb | 8 ++++++++ 3 files changed, 49 insertions(+) diff --git a/lib/rails/html/scrubbers.rb b/lib/rails/html/scrubbers.rb index 6182abb..7dde73a 100644 --- a/lib/rails/html/scrubbers.rb +++ b/lib/rails/html/scrubbers.rb @@ -134,6 +134,12 @@ def validate!(var, name) if var && !var.is_a?(Enumerable) raise ArgumentError, "You should pass :#{name} as an Enumerable" end + + if var && name == :tags && var.include?("noscript") + warn("WARNING: 'noscript' tags cannot be allowed by the PermitScrubber and will be scrubbed") + var.delete("noscript") + end + var end diff --git a/test/sanitizer_test.rb b/test/sanitizer_test.rb index 8cfb523..05c4130 100644 --- a/test/sanitizer_test.rb +++ b/test/sanitizer_test.rb @@ -1026,6 +1026,24 @@ def test_should_sanitize_across_newlines assert_equal "", sanitize_css(raw) end + def test_should_prune_noscript + # https://hackerone.com/reports/2509647 + input, tags = "