Merge remote-tracking branch 'glitch/main' (660372d130)
ci/woodpecker/push/woodpecker Pipeline failed Details

streaming-builds
kouhai dev 2023-11-27 23:00:43 -08:00
commit bcc0a24acd
3 changed files with 50 additions and 46 deletions

View File

@ -5,7 +5,7 @@ import { createRoot } from 'react-dom/client';
import { IntlMessageFormat } from 'intl-messageformat'; import { IntlMessageFormat } from 'intl-messageformat';
import { defineMessages } from 'react-intl'; import { defineMessages } from 'react-intl';
import delegate from '@rails/ujs'; import Rails from '@rails/ujs';
import axios from 'axios'; import axios from 'axios';
import { throttle } from 'lodash'; import { throttle } from 'lodash';
@ -129,7 +129,7 @@ function loaded() {
}); });
} }
delegate(document, '#user_account_attributes_username', 'input', throttle(({ target }) => { Rails.delegate(document, '#user_account_attributes_username', 'input', throttle(({ target }) => {
if (target.value && target.value.length > 0) { if (target.value && target.value.length > 0) {
axios.get('/api/v1/accounts/lookup', { params: { acct: target.value } }).then(() => { axios.get('/api/v1/accounts/lookup', { params: { acct: target.value } }).then(() => {
target.setCustomValidity(formatMessage(messages.usernameTaken)); target.setCustomValidity(formatMessage(messages.usernameTaken));
@ -141,7 +141,7 @@ function loaded() {
} }
}, 500, { leading: false, trailing: true })); }, 500, { leading: false, trailing: true }));
delegate(document, '#user_password,#user_password_confirmation', 'input', () => { Rails.delegate(document, '#user_password,#user_password_confirmation', 'input', () => {
const password = document.getElementById('user_password'); const password = document.getElementById('user_password');
const confirmation = document.getElementById('user_password_confirmation'); const confirmation = document.getElementById('user_password_confirmation');
if (!confirmation) return; if (!confirmation) return;
@ -155,7 +155,7 @@ function loaded() {
} }
}); });
delegate(document, '.status__content__spoiler-link', 'click', function() { Rails.delegate(document, '.status__content__spoiler-link', 'click', function() {
const statusEl = this.parentNode.parentNode; const statusEl = this.parentNode.parentNode;
if (statusEl.dataset.spoiler === 'expanded') { if (statusEl.dataset.spoiler === 'expanded') {
@ -192,23 +192,23 @@ const toggleSidebar = () => {
sidebar.classList.toggle('visible'); sidebar.classList.toggle('visible');
}; };
delegate(document, '.sidebar__toggle__icon', 'click', () => { Rails.delegate(document, '.sidebar__toggle__icon', 'click', () => {
toggleSidebar(); toggleSidebar();
}); });
delegate(document, '.sidebar__toggle__icon', 'keydown', e => { Rails.delegate(document, '.sidebar__toggle__icon', 'keydown', e => {
if (e.key === ' ' || e.key === 'Enter') { if (e.key === ' ' || e.key === 'Enter') {
e.preventDefault(); e.preventDefault();
toggleSidebar(); toggleSidebar();
} }
}); });
delegate(document, '.custom-emoji', 'mouseover', ({ target }) => target.src = target.getAttribute('data-original')); Rails.delegate(document, '.custom-emoji', 'mouseover', ({ target }) => target.src = target.getAttribute('data-original'));
delegate(document, '.custom-emoji', 'mouseout', ({ target }) => target.src = target.getAttribute('data-static')); Rails.delegate(document, '.custom-emoji', 'mouseout', ({ target }) => target.src = target.getAttribute('data-static'));
// Empty the honeypot fields in JS in case something like an extension // Empty the honeypot fields in JS in case something like an extension
// automatically filled them. // automatically filled them.
delegate(document, '#registration_new_user,#new_user', 'submit', () => { Rails.delegate(document, '#registration_new_user,#new_user', 'submit', () => {
['user_website', 'user_confirm_password', 'registration_user_website', 'registration_user_confirm_password'].forEach(id => { ['user_website', 'user_confirm_password', 'registration_user_website', 'registration_user_confirm_password'].forEach(id => {
const field = document.getElementById(id); const field = document.getElementById(id);
if (field) { if (field) {

View File

@ -14,17 +14,6 @@ def host_to_url(str)
uri.to_s uri.to_s
end end
base_host = Rails.configuration.x.web_domain
assets_host = Rails.configuration.action_controller.asset_host
assets_host ||= host_to_url(base_host)
media_host = host_to_url(ENV['S3_ALIAS_HOST'])
media_host ||= host_to_url(ENV['S3_CLOUDFRONT_HOST'])
media_host ||= host_to_url(ENV['AZURE_ALIAS_HOST'])
media_host ||= host_to_url(ENV['S3_HOSTNAME']) if ENV['S3_ENABLED'] == 'true'
media_host ||= assets_host
def sso_host def sso_host
return unless ENV['ONE_CLICK_SSO_LOGIN'] == 'true' return unless ENV['ONE_CLICK_SSO_LOGIN'] == 'true'
return unless ENV['OMNIAUTH_ONLY'] == 'true' return unless ENV['OMNIAUTH_ONLY'] == 'true'
@ -43,15 +32,43 @@ def sso_host
end end
end end
Rails.application.config.content_security_policy do |p| unless Rails.env.development?
assets_host = Rails.configuration.action_controller.asset_host || "https://#{ENV['WEB_DOMAIN'] || ENV['LOCAL_DOMAIN']}"
data_hosts = [assets_host]
if ENV['S3_ENABLED'] == 'true' || ENV['AZURE_ENABLED'] == 'true'
attachments_host = host_to_url(ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST'] || ENV['AZURE_ALIAS_HOST'] || ENV['S3_HOSTNAME'] || "s3-#{ENV['S3_REGION'] || 'us-east-1'}.amazonaws.com")
elsif ENV['SWIFT_ENABLED'] == 'true'
attachments_host = ENV['SWIFT_OBJECT_URL']
attachments_host = "https://#{Addressable::URI.parse(attachments_host).host}"
else
attachments_host = nil
end
data_hosts << attachments_host unless attachments_host.nil?
if ENV['PAPERCLIP_ROOT_URL']
url = Addressable::URI.parse(assets_host) + ENV['PAPERCLIP_ROOT_URL']
data_hosts << "https://#{url.host}"
end
data_hosts.concat(ENV['EXTRA_DATA_HOSTS'].split('|')) if ENV['EXTRA_DATA_HOSTS']
data_hosts.uniq!
Rails.application.config.content_security_policy do |p|
p.base_uri :none p.base_uri :none
p.default_src :none p.default_src :none
p.frame_ancestors :none p.frame_ancestors :none
p.script_src :self, assets_host, "'wasm-unsafe-eval'"
p.font_src :self, assets_host p.font_src :self, assets_host
p.img_src :self, :data, :blob, assets_host, media_host p.img_src :self, :data, :blob, *data_hosts
p.style_src :self, assets_host p.style_src :self, assets_host
p.media_src :self, :data, assets_host, media_host p.media_src :self, :data, *data_hosts
p.frame_src :self, :https p.frame_src :self, :https
p.child_src :self, :blob, assets_host
p.worker_src :self, :blob, assets_host
p.connect_src :self, :blob, :data, Rails.configuration.x.streaming_api_base_url, *data_hosts
p.manifest_src :self, assets_host p.manifest_src :self, assets_host
if sso_host.present? if sso_host.present?
@ -59,19 +76,6 @@ Rails.application.config.content_security_policy do |p|
else else
p.form_action :self p.form_action :self
end end
p.child_src :self, :blob, assets_host
p.worker_src :self, :blob, assets_host
if Rails.env.development?
webpacker_public_host = ENV.fetch('WEBPACKER_DEV_SERVER_PUBLIC', Webpacker.config.dev_server[:public])
webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{webpacker_public_host}" }
p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls
p.script_src :self, :unsafe_inline, :unsafe_eval, assets_host
else
p.connect_src :self, :data, :blob, assets_host, media_host, Rails.configuration.x.streaming_api_base_url
p.script_src :self, assets_host, "'wasm-unsafe-eval'"
end end
end end

View File

@ -12,15 +12,15 @@ describe 'Content-Security-Policy' do
"default-src 'none'", "default-src 'none'",
"frame-ancestors 'none'", "frame-ancestors 'none'",
"font-src 'self' https://cb6e6126.ngrok.io", "font-src 'self' https://cb6e6126.ngrok.io",
"img-src 'self' data: blob: https://cb6e6126.ngrok.io https://cb6e6126.ngrok.io", "img-src 'self' data: blob: https://cb6e6126.ngrok.io",
"style-src 'self' https://cb6e6126.ngrok.io 'nonce-ZbA+JmE7+bK8F5qvADZHuQ=='", "style-src 'self' https://cb6e6126.ngrok.io 'nonce-ZbA+JmE7+bK8F5qvADZHuQ=='",
"media-src 'self' data: https://cb6e6126.ngrok.io https://cb6e6126.ngrok.io", "media-src 'self' data: https://cb6e6126.ngrok.io",
"frame-src 'self' https:", "frame-src 'self' https:",
"manifest-src 'self' https://cb6e6126.ngrok.io", "manifest-src 'self' https://cb6e6126.ngrok.io",
"form-action 'self'", "form-action 'self'",
"child-src 'self' blob: https://cb6e6126.ngrok.io", "child-src 'self' blob: https://cb6e6126.ngrok.io",
"worker-src 'self' blob: https://cb6e6126.ngrok.io", "worker-src 'self' blob: https://cb6e6126.ngrok.io",
"connect-src 'self' data: blob: https://cb6e6126.ngrok.io https://cb6e6126.ngrok.io ws://localhost:4000", "connect-src 'self' blob: data: ws://localhost:4000 https://cb6e6126.ngrok.io",
"script-src 'self' https://cb6e6126.ngrok.io 'wasm-unsafe-eval'" "script-src 'self' https://cb6e6126.ngrok.io 'wasm-unsafe-eval'"
) )
end end