Security
Core security services and context-aware output protection.
Security Components
APPNETOS provides a shared security facade and dedicated controllers for context-aware output escaping, HTML sanitization and XSS handling. Select the correct protection for the output context; input filtering is not a substitute for context-specific output encoding.
These components are independent of user and group collections. Authentication and authorization are documented under User & Authentication.
Public API Reference
Core\Security
Class & Registry
Class:
Core\Security
Extends:
Core\Security\Base
use Core\Security;
use Core\Registry;
$security = Registry::get(Security::class);
| Method | Description |
|---|---|
public function html(string|null $value): string |
Escape HTML output |
public function attribute(string|null $value): string |
Escape HTML attribute output |
public function javascript(string|null $value): string |
Escape JavaScript string output |
public function url(string|null $value): string |
Escape URL component |
public function sanitizeHtml(string|null $value): string |
Sanitize HTML content |
public function stripPhp(string|null $value): string |
Strip PHP tags |
public function text(string|null $value): string |
Normalize plain text input |
Core\Security\Escaper
Class & Registry
Class:
Core\Security\Escaper
Extends:
Core\Security\Escaper\Base
use Core\Security\Escaper;
use Core\Registry;
$escaper = Registry::get(Escaper::class);
| Method | Description |
|---|---|
public function html(string|null $value): string |
Escape HTML output |
public function attribute(string|null $value): string |
Escape HTML attribute output |
public function javascript(string|null $value): string |
Escape JavaScript string output |
public function url(string|null $value): string |
Escape URL component |
public function css(string|null $value): string |
Sanitize CSS output |
public function json(mixed $value): string |
Encode JSON output |
public function text(string|null $value): string |
Sanitize plain text output |
Core\Security\HtmlSanitizer
Class & Registry
Class:
Core\Security\HtmlSanitizer
Extends:
Core\Security\HtmlSanitizer\Base
use Core\SecurityHtmlSanitizer;
use Core\Registry;
$htmlSanitizer = Registry::get(HtmlSanitizer::class);
| Method | Description |
|---|---|
public function sanitize(string|null $html): string |
Sanitize HTML content |
public function getAllowedTags(): array |
Get allowed HTML tags |
public function setAllowedTags(array $allowedTags): static |
Set allowed HTML tags |
public function getAllowedAttributes(): array |
Get allowed HTML attributes |
public function setAllowedAttributes(array $allowedAttributes): static
|
Set allowed HTML attributes |
public function getAllowedProtocols(): array |
Get allowed URI protocols |
public function setAllowedProtocols(array $allowedProtocols): static
|
Set allowed URI protocols |
Core\Security\Xss
Class & Registry
Class:
Core\Security\Xss
Extends:
Core\Security\Xss\Base
use Core\Security\Xss;
use Core\Registry;
$xss = Registry::get(Xss::class);
| Method | Description |
|---|---|
public function text(string|null $input): string |
Clean plain text input |
public function stripPhp(string|null $input): string |
Strip PHP tags |
public function stripScripts(string|null $input): string |
Strip script elements |
public function html(string|null $input): string |
Sanitize HTML content |
public function containsScripts(string|null $input): bool |
Check if content contains script elements |
public function containsPhp(string|null $input): bool |
Check if content contains PHP tags |