Class: ActionDispatch::ContentSecurityPolicy
- Inherits:
-
Object
- Object
- ActionDispatch::ContentSecurityPolicy
show all
- Defined in:
- lib/action_dispatch/http/content_security_policy.rb
Defined Under Namespace
Modules: Request
Classes: Middleware
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ContentSecurityPolicy.
133
134
135
136
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 133
def initialize
@directives = {}
yield self if block_given?
end
|
Instance Attribute Details
#directives ⇒ Object
Returns the value of attribute directives.
131
132
133
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 131
def directives
@directives
end
|
Instance Method Details
#block_all_mixed_content(enabled = true) ⇒ Object
152
153
154
155
156
157
158
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 152
def block_all_mixed_content(enabled = true)
if enabled
@directives["block-all-mixed-content"] = true
else
@directives.delete("block-all-mixed-content")
end
end
|
#build(context = nil, nonce = nil) ⇒ Object
198
199
200
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 198
def build(context = nil, nonce = nil)
build_directives(context, nonce).compact.join("; ")
end
|
#initialize_copy(other) ⇒ Object
138
139
140
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 138
def initialize_copy(other)
@directives = other.directives.deep_dup
end
|
#plugin_types(*types) ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 160
def plugin_types(*types)
if types.first
@directives["plugin-types"] = types
else
@directives.delete("plugin-types")
end
end
|
#report_uri(uri) ⇒ Object
168
169
170
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 168
def report_uri(uri)
@directives["report-uri"] = [uri]
end
|
#require_sri_for(*types) ⇒ Object
172
173
174
175
176
177
178
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 172
def require_sri_for(*types)
if types.first
@directives["require-sri-for"] = types
else
@directives.delete("require-sri-for")
end
end
|
#sandbox(*values) ⇒ Object
180
181
182
183
184
185
186
187
188
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 180
def sandbox(*values)
if values.empty?
@directives["sandbox"] = true
elsif values.first
@directives["sandbox"] = values
else
@directives.delete("sandbox")
end
end
|
#upgrade_insecure_requests(enabled = true) ⇒ Object
190
191
192
193
194
195
196
|
# File 'lib/action_dispatch/http/content_security_policy.rb', line 190
def upgrade_insecure_requests(enabled = true)
if enabled
@directives["upgrade-insecure-requests"] = true
else
@directives.delete("upgrade-insecure-requests")
end
end
|