Skip to content

Commit 08ac810

Browse files
committed
fix: solve CSP mismatch for sidekiq
o Sidekiq já injeta seu próprio CSP permissivo com nonce — só precisamos não sobrescrever com o restritivo
1 parent 252b822 commit 08ac810

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/middleware/security_headers.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ def initialize(app)
2828
@app = app
2929
end
3030

31-
SIDEKIQ_CSP = "default-src 'self'; img-src 'self' data:; " \
32-
"style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'".freeze
33-
3431
def call(env)
32+
# Capture path before @app.call — Rails mutates PATH_INFO during routing
33+
path = env['PATH_INFO']
3534
status, headers, body = @app.call(env)
3635

37-
if env['PATH_INFO'].start_with?('/sidekiq')
36+
if path.start_with?('/sidekiq')
37+
# Rack 3 normalises header keys to lowercase; delete both variants to be safe.
38+
# Sidekiq::Web already injects its own permissive CSP with nonce, so we just
39+
# remove the restrictive one added by ActionDispatch / our own HEADERS hash.
3840
headers.delete('Content-Security-Policy')
39-
headers['Content-Security-Policy'] = SIDEKIQ_CSP
41+
headers.delete('content-security-policy')
4042
return [status, headers, body]
4143
end
4244

0 commit comments

Comments
 (0)