PHP Classes

File: examples/case-studies/security/headers/security_header_authentication_management/security_header_authentication_management-GR.md

Recommend this page to a friend!
  Packages of Christos Drogidis   Ascoos OS   examples/case-studies/security/headers/security_header_authentication_management/security_header_authentication_management-GR.md   Download  
File: examples/case-studies/security/headers/security_header_authentication_management/security_header_authentication_management-GR.md
Role: Documentation
Content type: text/markdown
Description: Advanced Security Header Management with Authentication
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change:
Date: 6 months ago
Size: 6,812 bytes
 

Contents

Class file image Download

????????? ?????????? Headers ????????? ?? ???????????????

???? ? ?????? ?????????? ??????? ??? ?? Ascoos OS, ??? Full Modular PHP Web5 Kernel, ????????????? Content Security Policy (CSP), Cross-Origin Resource Sharing (CORS), headers ????????? ??? ??????????????? ??????? ??????????????? ??? modular ??????? ???. ??????????? ?? ??????? headers, ??? ????????? SSL/TLS, ?? ?????????? ????????? ??? ??? ?????????.

??????

  • ??????? ??? ???????? CSP, CORS ??? headers ????????? ???? ????????? ??????? (HTTP headers, `.htaccess`).
  • ??????????????? ??????? ???? ??? ???????? headers.
  • ????????? ?????????????? SSL/TLS ??? ???????? ?????????? ??????? CSP.
  • ????????? ????????? ????????? ??? ????????? ???????????????? ?? `TLoggerHandler`.
  • ??????? ????????? ??? ??????????????? ??? ???????? headers ?? `TEventHandler`.
  • ?????????? ???????? JSON ??? ???????.

?????? ??????? ??? Ascoos OS

  • TCSPHandler: ????????????? ??????? Content Security Policy (CSP).
  • TCORSHeaderHandler: ???????? headers CORS ??? cross-origin ???????????.
  • TSecurityHeaderHandler: ????????? headers ????????? (?.?. HSTS, X-Frame-Options).
  • TCustomHeaderHandler: ????????????? ????????????? headers.
  • THTTPHeaderHandler: ???????? ?????????? ???? ??? headers.
  • TApacheHandler: ??????? ????????????? SSL/TLS ??? ????????????? ???????????? Apache.
  • THTAccessHandler: ????????????? ?????? `.htaccess` ??? server-level ?????????.
  • TLoggerHandler: ?????????? ???????? ??? ????????? ????????????????.
  • TFilesHandler: ?????????? ??? ?????????? ???????? JSON.
  • TEventHandler: ????????????? ??????? ??? ??????? ?????????.
  • TAuthenticationHandler: ????????????? ??? ??????????????? ???????.

???? ???????

? ????????? ?????????? ?? ??? ?????? PHP: - security_header_authentication_management.php

??????????????

  1. PHP ? 8.2
  2. ????????????? Ascoos OS ? AWES 26

??? ?????????

  1. ??????? ??????? CSP, CORS, security ??? custom headers.
  2. ???????????? handlers (`TCSPHandler`, `TCORSHeaderHandler`, ?.??.) ?? ????????????? ???????? ?????????.
  3. ??????? ????????? ???????????????? ??? ????????? ?? `TEventHandler`.
  4. ??????????????? ??????? ?? `TAuthenticationHandler`, ??????? ????????? `auth.success` ? `auth.failed`.
  5. ??????? ??????????? ?????????????? SSL/TLS ?? `TApacheHandler` ??? ?????????? CSP ?? ??????????.
  6. ???????? CSP ??? CORS ??? `.htaccess` ?? `THTAccessHandler`.
  7. ???????? headers ???? HTTP ?? `THTTPHeaderHandler` ??? ??????? ????????? `security.header_applied`.
  8. ????????? ????????? ??? ????????? headers ?? `TLoggerHandler`.
  9. ?????????? ??? ?????????? ???????? JSON ?? `TFilesHandler`.
  10. ???????????? ?????.

?????????? ??????

$cspRules = [
    'default-src' => "'self'",
    'script-src' => "'self' https://test.loc",
    'report-uri' => 'https://report.test.loc/csp-report'
];
$corsRules = ['Access-Control-Allow-Origin' => 'https://trusted.domain.com'];
$securityRules = ['Strict-Transport-Security' => 'max-age=31536000'];

$cspHandler = new TCSPHandler($cspRules, ['sendMethod' => TCSPHandler::CSP_SEND_METHOD_HEADER]);
$httpHeaderHandler = new THTTPHeaderHandler();
$httpHeaderHandler->addHandler('CSP', $cspHandler);

$eventHandler = new TEventHandler();
$eventHandler->register('auth', 'auth.success', fn($credentials) => error_log("Login succeeded"));
$authHandler = new TAuthenticationHandler();
$authHandler->setEventHandler($eventHandler);

if ($authHandler->authenticate(['username' => 'admin', 'password' => 'pass'])) {
    $eventHandler->trigger('auth', 'auth.success', ['username' => 'admin']);
    $httpHeaderHandler->sendHeaders();
}

??????????? ??????????

  • HTTP Headers:
    Content-Security-Policy: default-src 'self'; script-src 'self' https://test.loc; report-uri https://report.test.loc/csp-report
    Access-Control-Allow-Origin: https://trusted.domain.com
    Strict-Transport-Security: max-age=31536000
    
  • ??????? JSON (`security_report_20251003_1828.json`):
    {
        "ssl_status": { "is_expired": false },
        "csp_rules": { "default-src": "'self'", ... },
        "cors_rules": { "Access-Control-Allow-Origin": "https://trusted.domain.com", ... },
        "security_rules": { "Strict-Transport-Security": "max-age=31536000" },
        "auth_status": { "user": "admin", "success": true, "errors": [] }
    }
    
  • ?????? Log (`security_headers.log`):
    [2025-10-03 18:28:00] INFO: Authentication succeeded for user: {"username":"admin"}
    [2025-10-03 18:28:00] INFO: Headers sent: {...}
    [2025-10-03 18:28:00] INFO: Security report saved to ./reports/security_report_20251003_1828.json
    

?????

??????????

????????? ?? case study ???????????? ?????????? ??????? CSP, ?????????????? ????????? APIs ? ???? ???????? ????????????????. ????? ?? CONTRIBUTING.md ??? ???????.

????? ??????

?????????? ??? ??? Ascoos General License (AGL). ????? ?? LICENSE.md.