Skip to content

Commit

Permalink
mozillaGH-36 Update RateLimitedCSPMiddleware to support csp_select de…
Browse files Browse the repository at this point in the history
…corator
  • Loading branch information
DylanYoung committed May 24, 2022
1 parent 02d06bc commit c7bde5c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions csp/contrib/rate_limiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class RateLimitedCSPMiddleware(CSPMiddleware):
to report-uri by excluding it from some requests."""

def build_policy(self, request, response):
config = getattr(response, '_csp_config', None)
update = getattr(response, '_csp_update', None)
build_kwargs = {
key: getattr(response, '_csp_%s' % key, None)
for key in ('config', 'update', 'select')
}
replace = getattr(response, '_csp_replace', {})
nonce = getattr(request, '_csp_nonce', None)

Expand All @@ -21,5 +23,8 @@ def build_policy(self, request, response):
if not include_report_uri:
replace['report-uri'] = None

return build_policy(config=config, update=update, replace=replace,
nonce=nonce)
return build_policy(
replace=replace,
nonce=nonce,
**build_kwargs,
)

0 comments on commit c7bde5c

Please sign in to comment.