41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
function send_app_csp_header(): void
|
|
{
|
|
if (headers_sent()) {
|
|
return;
|
|
}
|
|
|
|
header('Content-Security-Policy: ' . implode(' ', [
|
|
"script-src 'self' 'unsafe-inline' https://unpkg.com https://cdn.paddle.com;",
|
|
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;",
|
|
"font-src https://fonts.gstatic.com;",
|
|
"img-src 'self' data:;",
|
|
"connect-src 'self' https://cdn.paddle.com https://api.paddle.com https://sandbox-api.paddle.com;",
|
|
"frame-src https://buy.paddle.com https://sandbox-buy.paddle.com;",
|
|
"object-src 'none';",
|
|
"base-uri 'self';",
|
|
"frame-ancestors 'none';",
|
|
]), true, 0);
|
|
}
|
|
|
|
function start_app_session(): void
|
|
{
|
|
send_app_csp_header();
|
|
|
|
if (session_status() === PHP_SESSION_ACTIVE) {
|
|
return;
|
|
}
|
|
$isHttps = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|
|
|| (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https')
|
|
|| (($_SERVER['SERVER_PORT'] ?? '') === '443');
|
|
|
|
session_set_cookie_params([
|
|
'lifetime' => 0,
|
|
'path' => '/',
|
|
'secure' => $isHttps,
|
|
'httponly' => true,
|
|
'samesite' => 'Strict',
|
|
]);
|
|
session_start();
|
|
}
|