Context-specific encoding helpers, CsrfHelper split - #157
Merged
Conversation
HtmlHelper is now dependency-free with context-specific encoding:
- Html::url() — scheme validation (rejects javascript:, data:, etc.)
- Html::js() — JS string encoding (\uHHHH whitelist)
- Html::attr() — strict HTML attribute encoding (&#xHH;)
- Html::css() — CSS hex encoding (\HEX)
Plus existing nonce() and classIf().
CsrfHelper owns the ActiveSession dependency with field() and
token(). Registered as Csrf alias. {{ csrf }} directive updated
to Csrf::field().
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shodo README: encoding context guide with Html::url/js/attr/css
examples, updated helper table (Html is now dependency-free, Csrf
owns ActiveSession), {{ csrf }} maps to Csrf::field().
Htmx README: Html::csrfToken() → Csrf::token().
COMPENDIUM: built-in helpers listed in Shodo description.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Starter app Csrf references are the only remaining item — separate repo, will update when this PR merges. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
young-steveo
added a commit
to arcanum-org/arcanum
that referenced
this pull request
Apr 12, 2026
Framework split CsrfHelper from HtmlHelper (arcanum-org/framework#157). CSRF methods now live on the Csrf alias. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CsrfHelperfromHtmlHelper— CSRF methods (field(),token()) moved to a dedicatedCsrfHelperthat owns theActiveSessiondependency. Registered asCsrfalias.{{ csrf }}directive updated toCsrf::field().HtmlHelperis now dependency-free with four OWASP-aligned encoding methods:Html::url($href)— URL scheme validation (rejectsjavascript:,data:, etc.)Html::js($value)— JavaScript string encoding (whitelist, non-alphanumeric →\uHHHH)Html::attr($value)— strict HTML attribute encoding (non-alphanumeric →&#xHH;)Html::css($value)— CSS hex encoding (non-alphanumeric →\HEX)Htmlhelper always available — no longer gated behindActiveSessioncheck in bootstrapCsrf::token()), COMPENDIUM with built-in helper listHtml::csrf()→Csrf::field()andHtml::csrfToken()→Csrf::token()Test plan
composer checkpasses (cs-fix, phpstan level 9, phpunit — 2774 tests, 5546 assertions)Csrf::field()directiveGenerated with Claude Code