@@ -39,6 +39,7 @@ def self.included(base)
3939 SCRIPT_SRC = :script_src
4040 STYLE_SRC = :style_src
4141 REPORT_URI = :report_uri
42+ REPORT_TO = :report_to
4243
4344 DIRECTIVES_1_0 = [
4445 DEFAULT_SRC ,
@@ -51,7 +52,8 @@ def self.included(base)
5152 SANDBOX ,
5253 SCRIPT_SRC ,
5354 STYLE_SRC ,
54- REPORT_URI
55+ REPORT_URI ,
56+ REPORT_TO
5557 ] . freeze
5658
5759 BASE_URI = :base_uri
@@ -110,9 +112,9 @@ def self.included(base)
110112
111113 ALL_DIRECTIVES = ( DIRECTIVES_1_0 + DIRECTIVES_2_0 + DIRECTIVES_3_0 + DIRECTIVES_EXPERIMENTAL ) . uniq . sort
112114
113- # Think of default-src and report-uri as the beginning and end respectively,
115+ # Think of default-src and report-uri/report-to as the beginning and end respectively,
114116 # everything else is in between.
115- BODY_DIRECTIVES = ALL_DIRECTIVES - [ DEFAULT_SRC , REPORT_URI ]
117+ BODY_DIRECTIVES = ALL_DIRECTIVES - [ DEFAULT_SRC , REPORT_URI , REPORT_TO ]
116118
117119 DIRECTIVE_VALUE_TYPES = {
118120 BASE_URI => :source_list ,
@@ -132,6 +134,7 @@ def self.included(base)
132134 REQUIRE_SRI_FOR => :require_sri_for_list ,
133135 REQUIRE_TRUSTED_TYPES_FOR => :require_trusted_types_for_list ,
134136 REPORT_URI => :source_list ,
137+ REPORT_TO => :report_to_endpoint ,
135138 PREFETCH_SRC => :source_list ,
136139 SANDBOX => :sandbox_list ,
137140 SCRIPT_SRC => :source_list ,
@@ -159,6 +162,7 @@ def self.included(base)
159162 FRAME_ANCESTORS ,
160163 NAVIGATE_TO ,
161164 REPORT_URI ,
165+ REPORT_TO ,
162166 ]
163167
164168 FETCH_SOURCES = ALL_DIRECTIVES - NON_FETCH_SOURCES - NON_SOURCE_LIST_SOURCES
@@ -344,6 +348,8 @@ def validate_directive!(directive, value)
344348 validate_require_sri_source_expression! ( directive , value )
345349 when :require_trusted_types_for_list
346350 validate_require_trusted_types_for_source_expression! ( directive , value )
351+ when :report_to_endpoint
352+ validate_report_to_endpoint_expression! ( directive , value )
347353 else
348354 raise ContentSecurityPolicyConfigError . new ( "Unknown directive #{ directive } " )
349355 end
@@ -398,6 +404,18 @@ def validate_require_trusted_types_for_source_expression!(directive, require_tru
398404 end
399405 end
400406
407+ # Private: validates that a report-to endpoint expression:
408+ # 1. is a string
409+ # 2. is not empty
410+ def validate_report_to_endpoint_expression! ( directive , endpoint_name )
411+ unless endpoint_name . is_a? ( String )
412+ raise ContentSecurityPolicyConfigError . new ( "#{ directive } must be a string. Found #{ endpoint_name . class } value" )
413+ end
414+ if endpoint_name . empty?
415+ raise ContentSecurityPolicyConfigError . new ( "#{ directive } must not be empty" )
416+ end
417+ end
418+
401419 # Private: validates that a source expression:
402420 # 1. is an array of strings
403421 # 2. does not contain any deprecated, now invalid values (inline, eval, self, none)
0 commit comments