Compare commits

...

2 commits

Author SHA1 Message Date
735ca6c07b Upgrade to Rails 8.0.2 2025-03-29 14:45:51 -07:00
38bad12778 Fix item animations for asset URLs that contain unescaped spaces
Before this change, the "Ornamental Lake with Goldies" item would fail
to preview on the item page: the iframe for the animation layer would
display an error page.

The error was:

```
Invalid Content Security Policy script-src: "https://images.neopets.com/cp/items/data/000/000/497/497366_deca9f2827/497366_HTML5 Canvas.js". Directive values must not contain whitespace or semicolons. Please use multiple arguments or other directive methods instead. (ActionDispatch::ContentSecurityPolicy::InvalidDirectiveError)
```

This is because the URL that Neopets sends us for this JS file contains
an unescaped space character. This isn't usually an issue for e.g.
loading a URL in the browser, but it's *not* valid syntax for inclusion
in a Content Security Policy.

In this change, we update our CSP code to parse URLs into
`Addressable::URI` objects, which enables us to call the `normalize!`
method, which fixes oddities like that.

The URL now correctly appears in the CSP as
`https://images.neopets.com/cp/items/data/000/000/497/497366_deca9f2827/497366_HTML5%20Canvas.js`.
2025-03-29 14:45:41 -07:00
59 changed files with 87 additions and 74 deletions

View file

@ -7,29 +7,29 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actioncable (8.0.1)
actionpack (= 8.0.1)
activesupport (= 8.0.1)
actioncable (8.0.2)
actionpack (= 8.0.2)
activesupport (= 8.0.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
zeitwerk (~> 2.6)
actionmailbox (8.0.1)
actionpack (= 8.0.1)
activejob (= 8.0.1)
activerecord (= 8.0.1)
activestorage (= 8.0.1)
activesupport (= 8.0.1)
actionmailbox (8.0.2)
actionpack (= 8.0.2)
activejob (= 8.0.2)
activerecord (= 8.0.2)
activestorage (= 8.0.2)
activesupport (= 8.0.2)
mail (>= 2.8.0)
actionmailer (8.0.1)
actionpack (= 8.0.1)
actionview (= 8.0.1)
activejob (= 8.0.1)
activesupport (= 8.0.1)
actionmailer (8.0.2)
actionpack (= 8.0.2)
actionview (= 8.0.2)
activejob (= 8.0.2)
activesupport (= 8.0.2)
mail (>= 2.8.0)
rails-dom-testing (~> 2.2)
actionpack (8.0.1)
actionview (= 8.0.1)
activesupport (= 8.0.1)
actionpack (8.0.2)
actionview (= 8.0.2)
activesupport (= 8.0.2)
nokogiri (>= 1.8.5)
rack (>= 2.2.4)
rack-session (>= 1.0.1)
@ -37,35 +37,35 @@ GEM
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
useragent (~> 0.16)
actiontext (8.0.1)
actionpack (= 8.0.1)
activerecord (= 8.0.1)
activestorage (= 8.0.1)
activesupport (= 8.0.1)
actiontext (8.0.2)
actionpack (= 8.0.2)
activerecord (= 8.0.2)
activestorage (= 8.0.2)
activesupport (= 8.0.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (8.0.1)
activesupport (= 8.0.1)
actionview (8.0.2)
activesupport (= 8.0.2)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activejob (8.0.1)
activesupport (= 8.0.1)
activejob (8.0.2)
activesupport (= 8.0.2)
globalid (>= 0.3.6)
activemodel (8.0.1)
activesupport (= 8.0.1)
activerecord (8.0.1)
activemodel (= 8.0.1)
activesupport (= 8.0.1)
activemodel (8.0.2)
activesupport (= 8.0.2)
activerecord (8.0.2)
activemodel (= 8.0.2)
activesupport (= 8.0.2)
timeout (>= 0.4.0)
activestorage (8.0.1)
actionpack (= 8.0.1)
activejob (= 8.0.1)
activerecord (= 8.0.1)
activesupport (= 8.0.1)
activestorage (8.0.2)
actionpack (= 8.0.2)
activejob (= 8.0.2)
activerecord (= 8.0.2)
activesupport (= 8.0.2)
marcel (~> 1.0)
activesupport (8.0.1)
activesupport (8.0.2)
base64
benchmark (>= 0.3)
bigdecimal
@ -123,7 +123,7 @@ GEM
builder (3.3.0)
childprocess (5.1.0)
logger (~> 1.5)
concurrent-ruby (1.3.4)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
console (1.29.2)
fiber-annotation
@ -196,13 +196,14 @@ GEM
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.6)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
io-console (0.8.0)
io-endpoint (0.14.0)
io-event (1.7.5)
io-stream (0.6.1)
irb (1.14.3)
irb (1.15.1)
pp (>= 0.6.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jaro_winkler (1.6.0)
@ -227,7 +228,7 @@ GEM
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
localhost (1.3.1)
logger (1.6.5)
logger (1.7.0)
loofah (2.24.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
@ -242,24 +243,24 @@ GEM
metrics (0.12.1)
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.4)
minitest (5.25.5)
msgpack (1.7.5)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mysql2 (0.5.6)
net-http (0.6.0)
uri
net-imap (0.5.5)
net-imap (0.5.6)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.5.0)
net-smtp (0.5.1)
net-protocol
nio4r (2.7.4)
nokogiri (1.18.1)
nokogiri (1.18.6)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
omniauth (2.1.2)
@ -291,6 +292,9 @@ GEM
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pp (0.6.2)
prettyprint
prettyprint (0.2.0)
process-metrics (0.3.0)
console (~> 1.8)
json (~> 2)
@ -305,12 +309,12 @@ GEM
protocol-rack (0.10.1)
protocol-http (~> 0.37)
rack (>= 1.0)
psych (5.2.2)
psych (5.2.3)
date
stringio
public_suffix (6.0.1)
racc (1.8.1)
rack (3.1.8)
rack (3.1.12)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-mini-profiler (3.3.1)
@ -333,20 +337,20 @@ GEM
rack (>= 1.3)
rackup (2.2.1)
rack (>= 3)
rails (8.0.1)
actioncable (= 8.0.1)
actionmailbox (= 8.0.1)
actionmailer (= 8.0.1)
actionpack (= 8.0.1)
actiontext (= 8.0.1)
actionview (= 8.0.1)
activejob (= 8.0.1)
activemodel (= 8.0.1)
activerecord (= 8.0.1)
activestorage (= 8.0.1)
activesupport (= 8.0.1)
rails (8.0.2)
actioncable (= 8.0.2)
actionmailbox (= 8.0.2)
actionmailer (= 8.0.2)
actionpack (= 8.0.2)
actiontext (= 8.0.2)
actionview (= 8.0.2)
activejob (= 8.0.2)
activemodel (= 8.0.2)
activerecord (= 8.0.2)
activestorage (= 8.0.2)
activesupport (= 8.0.2)
bundler (>= 1.15.0)
railties (= 8.0.1)
railties (= 8.0.2)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
@ -357,9 +361,9 @@ GEM
rails-i18n (8.0.1)
i18n (>= 0.7, < 2)
railties (>= 8.0.0, < 9)
railties (8.0.1)
actionpack (= 8.0.1)
activesupport (= 8.0.1)
railties (8.0.2)
actionpack (= 8.0.2)
activesupport (= 8.0.2)
irb (~> 1.13)
rackup (>= 1.0.0)
rake (>= 12.2)
@ -369,7 +373,7 @@ GEM
rake (13.2.1)
rbs (2.8.4)
rdiscount (2.2.7.3)
rdoc (6.10.0)
rdoc (6.13.1)
psych (>= 4.0.0)
react-rails (2.7.1)
babel-transpiler (>= 0.7.0)
@ -469,7 +473,7 @@ GEM
activesupport (>= 6.1)
sprockets (>= 3.0.0)
stackprof (0.2.26)
stringio (3.1.2)
stringio (3.1.6)
swd (2.0.3)
activesupport (>= 3)
attr_required (>= 0.0.5)
@ -492,7 +496,7 @@ GEM
unicode-display_width (3.1.3)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.2)
uri (1.0.3)
useragent (0.16.11)
validate_url (1.0.15)
activemodel (>= 3.0.0)
@ -518,7 +522,7 @@ GEM
websocket-extensions (0.1.5)
will_paginate (4.0.1)
yard (0.9.37)
zeitwerk (2.7.1)
zeitwerk (2.7.2)
PLATFORMS
ruby

View file

@ -18,7 +18,7 @@ class SwfAssetsController < ApplicationController
# doing this can help make this header a *lot* shorter, which helps
# our nginx reverse proxy (and probably some clients) handle it. (For
# example, see asset `667993` for "Engulfed in Flames Effect".)
hosts: ["https://images.neopets.com"],
origins: ["https://images.neopets.com"],
)
}
@ -45,14 +45,23 @@ class SwfAssetsController < ApplicationController
private
def src_list(*urls, hosts: [])
urls.
def src_list(*urls, origins: [])
clean_urls = urls.
# Ignore any `nil`s that might arise
filter(&:present?).
# Parse the URL.
map { |url| Addressable::URI.parse(url) }.
# Remove query strings from URLs (they're invalid in CSPs)
map { |url| url.sub(/\?.*\z/, "") }.
# For the given `hosts`, remove all their specific URLs, and just list
# the host itself.
reject { |url| hosts.any? { |h| url.start_with? h } } + hosts
each { |url| url.query = nil }.
# For the given `origins`, remove all their specific URLs, because
# we'll just include the entire origin anyway.
reject { |url| origins.include?(url.origin) }.
# Normalize the URLs. (This fixes issues like when the canonical
# Neopets version of the URL contains plain unescaped spaces.)
each(&:normalize!).
# Convert the URLs back into strings.
map(&:to_s)
clean_urls + origins
end
end

Binary file not shown.

BIN
vendor/cache/actioncable-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actionmailbox-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actionmailer-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actionpack-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actiontext-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actionview-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activejob-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activemodel-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activerecord-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activestorage-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activesupport-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/concurrent-ruby-1.3.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/i18n-1.14.7.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/irb-1.15.1.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/logger-1.7.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/minitest-5.25.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/net-imap-0.5.6.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/net-smtp-0.5.1.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/pp-0.6.2.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/prettyprint-0.2.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/psych-5.2.3.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/rack-3.1.12.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rails-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/railties-8.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rdoc-6.13.1.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/stringio-3.1.6.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/uri-1.0.3.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/zeitwerk-2.7.2.gem vendored Normal file

Binary file not shown.