Skip to content

Commit

Permalink
Expand/extract list of ccTLDs, into construction loop
Browse files Browse the repository at this point in the history
  • Loading branch information
veganstraightedge committed Dec 27, 2024
1 parent 505049e commit 9ef01d8
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions app/middlewares/rack/domain_redirect.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Rack
class DomainRedirect
# subdomain (optional), path prefix (optional), URL regex to match (required)
REDIRECT_CONFIGS = [
MAIN_REDIRECT_CONFIGS = [
# SSfWD
['', '/steal-something-from-work-day', /stealfromwork.crimethinc.com$/],

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High

This regular expression has an unescaped '.' before 'crimethinc.com', so it might match more hosts than expected.
['', '/steal-something-from-work-day', /stealfromworkday.com$/],
Expand All @@ -22,30 +22,39 @@ class DomainRedirect
['cs.', '', /cz.crimethinc.com/], # Fix our orignal mistaken assumption

# short domain (for historical twitter/etc posts)
['', '', /cwc.im/],

# TEMP: work out better general purpose locale subdomain + short domain redirect
['ar.', '', /ar.cwc.im$/],
['cs.', '', /cs.cwc.im$/],
['cz.', '', /cz.cwc.im$/],
['da.', '', /da.cwc.im$/],
['de.', '', /de.cwc.im$/],
['en.', '', /en.cwc.im$/],
['es.', '', /es.cwc.im$/],
['fi.', '', /fi.cwc.im$/],
['fr.', '', /fr.cwc.im$/],
['gr.', '', /gr.cwc.im$/],
['he.', '', /he.cwc.im$/],
['id.', '', /id.cwc.im$/],
['in.', '', /in.cwc.im$/],
['it.', '', /it.cwc.im$/],
['pl.', '', /pl.cwc.im$/],
['pt.', '', /pt.cwc.im$/],
['ru.', '', /ru.cwc.im$/],
['sv.', '', /sv.cwc.im$/],
['tr.', '', /tr.cwc.im$/]
['', '', /cwc.im/]
].freeze

CC_TLD_SUBDOMAINS = %w[
ar
be bg bn
cs cz
da de dv
en es eu
fa fi fr
gl gr
he hu
id in it
ja
ko ku
nl no
pl pt
ro ru
sk sl sv
th tl tr
uk
vi
zh
].freeze

# TEMP: work out better general purpose locale subdomain + short domain redirect
CC_TLD_SHORT_DOMAIN_REDIRECT_CONFIGS = CC_TLD_SUBDOMAINS.map do |subdomain|
["#{subdomain}.", '', /#{subdomain}.cwc.im$/]
end.freeze

# combined redirect configs
REDIRECT_CONFIGS = (MAIN_REDIRECT_CONFIGS + CC_TLD_SHORT_DOMAIN_REDIRECT_CONFIGS).freeze

PROTOCOL = 'https://'.freeze
DOMAIN = 'crimethinc.com'.freeze

Expand Down

0 comments on commit 9ef01d8

Please sign in to comment.