feat(security): add Content-Security-Policy headers with strict script-src
Eliminate all inline scripts to enable script-src 'self' without 'unsafe-inline', providing strong XSS mitigation via CSP. Inline script removal: - login.phtml: replace inline APP_ASSET_BASE with data-asset-base attribute + app-boot.js (matching default.phtml pattern) - api-docs: extract SwaggerUI init to js/pages/admin-api-docs-index.js - docs: extract checkbox enablement to js/pages/admin-docs-index.js - language-switcher: replace onchange handler with data-auto-submit attribute + js/components/app-auto-submit.js event listener CSP policy (dev + prod nginx): default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'none'; manifest-src 'self' Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ server {
|
|||||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
||||||
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
||||||
|
add_header Content-Security-Policy "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'none'; manifest-src 'self';" always;
|
||||||
|
|
||||||
root /var/www/web;
|
root /var/www/web;
|
||||||
index index.php;
|
index index.php;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ server {
|
|||||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
||||||
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
||||||
|
add_header Content-Security-Policy "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'none'; manifest-src 'self'; upgrade-insecure-requests;" always;
|
||||||
|
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
}
|
}
|
||||||
@@ -30,6 +31,7 @@ server {
|
|||||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
|
||||||
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
add_header X-Permitted-Cross-Domain-Policies "none" always;
|
||||||
add_header Strict-Transport-Security "max-age=31536000" always;
|
add_header Strict-Transport-Security "max-age=31536000" always;
|
||||||
|
add_header Content-Security-Policy "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; form-action 'self'; base-uri 'self'; frame-ancestors 'none'; manifest-src 'self'; upgrade-insecure-requests;" always;
|
||||||
|
|
||||||
root /var/www/web;
|
root /var/www/web;
|
||||||
index index.php;
|
index index.php;
|
||||||
|
|||||||
@@ -8,29 +8,8 @@ require templatePath('partials/app-breadcrumb.phtml');
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="app-swagger-container">
|
<div class="app-swagger-container">
|
||||||
<div id="swagger-ui"></div>
|
<div id="swagger-ui" data-spec-url="<?php e($specUrl); ?>"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="<?php e(assetVersion('vendor/swagger-ui/swagger-ui-bundle.js')); ?>"></script>
|
<script src="<?php e(assetVersion('vendor/swagger-ui/swagger-ui-bundle.js')); ?>"></script>
|
||||||
<script>
|
<script type="module" src="<?php e(assetVersion('js/pages/admin-api-docs-index.js')); ?>"></script>
|
||||||
window.addEventListener('DOMContentLoaded', function () {
|
|
||||||
if (!window.SwaggerUIBundle) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.SwaggerUIBundle({
|
|
||||||
url: '<?php e($specUrl); ?>',
|
|
||||||
dom_id: '#swagger-ui',
|
|
||||||
deepLinking: false,
|
|
||||||
displayRequestDuration: true,
|
|
||||||
filter: true,
|
|
||||||
docExpansion: 'list',
|
|
||||||
supportedSubmitMethods: [],
|
|
||||||
tryItOutEnabled: false,
|
|
||||||
presets: [
|
|
||||||
window.SwaggerUIBundle.presets.apis,
|
|
||||||
],
|
|
||||||
layout: 'BaseLayout'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -70,10 +70,4 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script type="module" src="<?php e(assetVersion('js/pages/admin-docs-index.js')); ?>"></script>
|
||||||
window.addEventListener('DOMContentLoaded', function () {
|
|
||||||
document.querySelectorAll('.app-docs-content li > input[type="checkbox"][disabled]').forEach(function (checkbox) {
|
|
||||||
checkbox.removeAttribute('disabled');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -17,15 +17,14 @@ if ($bufferTitle !== '') {
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html
|
<html
|
||||||
data-theme="<?php e($theme); ?>"
|
data-theme="<?php e($theme); ?>"
|
||||||
|
data-asset-base="<?php e(asset('')); ?>"
|
||||||
data-password-toggle-show-label="<?php e(t('Show password')); ?>"
|
data-password-toggle-show-label="<?php e(t('Show password')); ?>"
|
||||||
data-password-toggle-hide-label="<?php e(t('Hide password')); ?>"
|
data-password-toggle-hide-label="<?php e(t('Hide password')); ?>"
|
||||||
<?php if ($primaryVars !== ''): ?>style="<?php e($primaryVars); ?>" <?php endif; ?>>
|
<?php if ($primaryVars !== ''): ?>style="<?php e($primaryVars); ?>" <?php endif; ?>>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
<script src="<?php e(assetVersion('js/app-boot.js')); ?>"></script>
|
||||||
<base href="<?php e(localeBase()); ?>">
|
<base href="<?php e(localeBase()); ?>">
|
||||||
<script>
|
|
||||||
window.APP_ASSET_BASE = "<?php e(asset('')); ?>";
|
|
||||||
</script>
|
|
||||||
<title><?php e($pageTitle); ?></title>
|
<title><?php e($pageTitle); ?></title>
|
||||||
<meta property="og:site_name" content="<?php e($defaultTitle); ?>">
|
<meta property="og:site_name" content="<?php e($defaultTitle); ?>">
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ $publicTarget = ltrim($publicTarget, '/');
|
|||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
<form class="nav nav--lang" method="get" action="<?php e($baseUrl); ?>" aria-label="<?php e(t('Language switcher')); ?>">
|
<form class="nav nav--lang" method="get" action="<?php e($baseUrl); ?>" aria-label="<?php e(t('Language switcher')); ?>">
|
||||||
<input type="hidden" name="return" value="<?php e($returnTarget); ?>">
|
<input type="hidden" name="return" value="<?php e($returnTarget); ?>">
|
||||||
<select class="lang-select" name="locale" onchange="this.form.submit()">
|
<select class="lang-select" name="locale" data-auto-submit>
|
||||||
<?php foreach ($locales as $locale): ?>
|
<?php foreach ($locales as $locale): ?>
|
||||||
<option value="<?php e($locale); ?>" <?php if ($locale === I18n::$locale) { ?>selected<?php } ?>>
|
<option value="<?php e($locale); ?>" <?php if ($locale === I18n::$locale) { ?>selected<?php } ?>>
|
||||||
<?php e(strtoupper((string) $locale)); ?>
|
<?php e(strtoupper((string) $locale)); ?>
|
||||||
|
|||||||
@@ -22,3 +22,4 @@ import './components/app-custom-field-options-toggle.js';
|
|||||||
import './components/app-tenant-sso-toggle.js';
|
import './components/app-tenant-sso-toggle.js';
|
||||||
import './components/app-settings-telemetry.js';
|
import './components/app-settings-telemetry.js';
|
||||||
import './components/app-standard-detail-page.js';
|
import './components/app-standard-detail-page.js';
|
||||||
|
import './components/app-auto-submit.js';
|
||||||
|
|||||||
12
web/js/components/app-auto-submit.js
Normal file
12
web/js/components/app-auto-submit.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Auto-submit: submits the parent form when a [data-auto-submit] element changes.
|
||||||
|
* Replaces inline onchange="this.form.submit()" handlers for CSP compliance.
|
||||||
|
*/
|
||||||
|
document.querySelectorAll('[data-auto-submit]').forEach((element) => {
|
||||||
|
element.addEventListener('change', () => {
|
||||||
|
const form = element.closest('form');
|
||||||
|
if (form) {
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
16
web/js/pages/admin-api-docs-index.js
Normal file
16
web/js/pages/admin-api-docs-index.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const container = document.getElementById('swagger-ui');
|
||||||
|
|
||||||
|
if (container && window.SwaggerUIBundle) {
|
||||||
|
window.SwaggerUIBundle({
|
||||||
|
url: container.dataset.specUrl || '',
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
deepLinking: false,
|
||||||
|
displayRequestDuration: true,
|
||||||
|
filter: true,
|
||||||
|
docExpansion: 'list',
|
||||||
|
supportedSubmitMethods: [],
|
||||||
|
tryItOutEnabled: false,
|
||||||
|
presets: [window.SwaggerUIBundle.presets.apis],
|
||||||
|
layout: 'BaseLayout',
|
||||||
|
});
|
||||||
|
}
|
||||||
3
web/js/pages/admin-docs-index.js
Normal file
3
web/js/pages/admin-docs-index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
document
|
||||||
|
.querySelectorAll('.app-docs-content li > input[type="checkbox"][disabled]')
|
||||||
|
.forEach((checkbox) => checkbox.removeAttribute('disabled'));
|
||||||
Reference in New Issue
Block a user