Skip to content

Commit 8e9fbb2

Browse files
authored
Merge pull request opf#20807 from opf/fix/68580-dynamic-csp-for-local-addresses
Allow dynamic CSP to define addresses without standard ports
2 parents c17e5a7 + 61fa598 commit 8e9fbb2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

app/controllers/concerns/dynamic_content_security_policy.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,14 @@ def add_hocuspocus_host_to_csp
6868
nil
6969
end
7070
if uri.present?
71-
append_content_security_policy_directives(connect_src: ["#{uri.scheme}://#{uri.host}"])
71+
append_content_security_policy_directives(connect_src: ["#{uri.scheme}://#{host_with_port(uri)}"])
7272
end
7373
end
7474
end
75+
76+
def host_with_port(uri)
77+
# Include port if it's not the default port for the scheme (necessary for local dev support)
78+
default_port = ["wss", "https"].include?(uri.scheme) ? 443 : 80
79+
uri.port && uri.port != default_port ? "#{uri.host}:#{uri.port}" : uri.host
80+
end
7581
end

0 commit comments

Comments
 (0)