First version of the security module

This commit is contained in:
2026-06-22 13:19:05 +02:00
parent 0392043ee3
commit 498afc7840
64 changed files with 7581 additions and 4 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace MintyPHP\Module\Security\Service;
use League\CommonMark\GithubFlavoredMarkdownConverter;
/**
* Renders check-template Markdown guidance to sanitized HTML.
*
* Hardened config: raw HTML in the source is escaped (html_input=escape) and
* unsafe links (javascript:, data:, …) are dropped (allow_unsafe_links=false),
* so author-entered content can never inject markup/script into the workspace.
*
* @api Consumed by the security check workspace action to pre-render per-item guidance.
*/
final class SecurityMarkdownGateway
{
private ?GithubFlavoredMarkdownConverter $converter = null;
public function toHtml(string $markdown): string
{
$markdown = trim($markdown);
if ($markdown === '') {
return '';
}
$this->converter ??= new GithubFlavoredMarkdownConverter([
'html_input' => 'escape',
'allow_unsafe_links' => false,
]);
return (string) $this->converter->convert($markdown);
}
}