From c7bde5c3196e393fbbcd92fc3a7e9fd7280f401f Mon Sep 17 00:00:00 2001 From: Dylan Young Date: Tue, 24 May 2022 02:03:02 -0300 Subject: [PATCH] GH-36 Update RateLimitedCSPMiddleware to support csp_select decorator --- csp/contrib/rate_limiting.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/csp/contrib/rate_limiting.py b/csp/contrib/rate_limiting.py index 8a4d087..724ae54 100644 --- a/csp/contrib/rate_limiting.py +++ b/csp/contrib/rate_limiting.py @@ -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) @@ -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, + )