Skip to content

Commit d297a8e

Browse files
committed
fix: solve duplicated CORS configuration
1 parent 455d916 commit d297a8e

3 files changed

Lines changed: 7 additions & 14 deletions

File tree

config/application.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,8 @@ class Application < Rails::Application
5353
config.autoload_paths += %W[#{config.root}/app/modules]
5454
config.eager_load_paths += %W[#{config.root}/app/modules]
5555

56-
# CORS configuration
57-
config.middleware.insert_before 0, Rack::Cors do
58-
allow do
59-
origins ENV.fetch('CORS_ORIGINS', 'http://localhost:8888').split(',')
60-
61-
resource '*',
62-
headers: :any,
63-
methods: %i[get post put patch delete options head],
64-
credentials: true,
65-
max_age: 86_400
66-
end
67-
end
56+
# CORS configuration - See config/initializers/cors.rb
57+
# Removed from here to avoid duplicate middleware registration
6858

6959
# Rack Attack for rate limiting
7060
config.middleware.use Rack::Attack

config/initializers/cors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rails.application.config.middleware.insert_before 0, Rack::Cors do
44
allow do
55
# The fallback (second argument) must be a single string separated by commas
6-
origins ENV.fetch('CORS_ORIGINS', 'http://localhost:5173,http://localhost:8888,https://prostaff.vercel.app,https://prostaff.gg,https://api.prostaff.gg').split(',')
6+
origins ENV.fetch('CORS_ORIGINS', 'http://localhost:5173,http://localhost:8888,https://prostaff.vercel.app,https://prostaff.gg,https://www.prostaff.gg,https://api.prostaff.gg').split(',')
77

88
resource '*',
99
headers: :any,

config/initializers/rack_attack.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ class Attack
5757
end
5858

5959
# Block suspicious requests (no user agent)
60+
# Allow OPTIONS requests (CORS preflight) even without user agent
6061
blocklist('block requests without user agent') do |req|
61-
req.user_agent.blank? && !['/health', '/up'].include?(req.path)
62+
req.user_agent.blank? &&
63+
!['/health', '/up'].include?(req.path) &&
64+
req.request_method != 'OPTIONS'
6265
end
6366

6467
# Block requests with suspicious patterns

0 commit comments

Comments
 (0)