Skip to content

Commit c0f16c1

Browse files
committed
Defer creation of Request object until the object is in need
1 parent 9c66072 commit c0f16c1

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

actionpack/lib/action_dispatch/http/content_security_policy.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def initialize(app)
3232
end
3333

3434
def call(env)
35-
request = ActionDispatch::Request.new env
3635
status, headers, _ = response = @app.call(env)
3736

3837
# Returning CSP headers with a 304 Not Modified is harmful, since nonces in the new
@@ -41,6 +40,8 @@ def call(env)
4140

4241
return response if policy_present?(headers)
4342

43+
request = ActionDispatch::Request.new env
44+
4445
if policy = request.content_security_policy
4546
nonce = request.content_security_policy_nonce
4647
nonce_directives = request.content_security_policy_nonce_directives

actionpack/lib/action_dispatch/http/permissions_policy.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ def initialize(app)
3434
end
3535

3636
def call(env)
37-
request = ActionDispatch::Request.new(env)
3837
_, headers, _ = response = @app.call(env)
3938

4039
return response unless html_response?(headers)
4140
return response if policy_present?(headers)
4241

42+
request = ActionDispatch::Request.new(env)
43+
4344
if policy = request.permissions_policy
4445
headers[POLICY] = policy.build(request.controller_instance)
4546
end

0 commit comments

Comments
 (0)