Repository navigation
test: add csrf_field view coverage (gin#258, fiber#313) - #162
Merged
Merged
Conversation
hwbrzzl
approved these changes
Oct 26, 2026
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
{{ csrf_field }}end-to-end under both drivers: the hidden_tokeninput reaches the page as raw HTML (template.HTML), while a hostile session token is HTML-escaped inside thevalueattribute.fillSharedassignability guard: rendering a view withmap[string]stringdata while a session exists skips shared values that cannot be assigned to the map element type instead of panicking, andcsrf_tokenis still merged in.github.com/goravel/gintov1.18.1-0.20261026033159-4d2c4e578ae1andgithub.com/goravel/fibertov1.18.1-0.20261026033240-13f6b8ac2d3c(the merged feat: Add {{ csrf_field }} template function gin#258 and feat: Add{{ csrf_field }}template function fiber#313 commits) so the coverage runs against the fixed behavior.Why
middleware.StartSession()is registered globally, so every view render carriescsrf_tokenandcsrf_fieldin the shared data. Before goravel/gin#258 and goravel/fiber#313 there was nocsrf_fieldat all, andfillSharedwrote shared values with an unguardedreflect.Value.SetMapIndex, which panics as soon as amap[string]stringview receives atemplate.HTMLvalue. This PR adds regression coverage for both halves of that fix in the existingViewTestSuite, whichtests/feature/fiber_test.goalready re-runs underTestFiberDriver, so neither driver can regress unnoticed.resources/views/admin/index.tmplandtests/feature/http_test.goare deliberately untouched — they are owned by the open #160.The templates render
{{ .csrf_token }}beside{{ .csrf_field }}, so a single full-body comparison fails loudly if the hidden input comes back escaped. Themap[string]stringcase needs no test-only session mutation: the fixed token is written through the normal test session helper.Dependency note: the
requireline forgithub.com/goravel/frameworkmoved tov1.18.1-0.20261019082352-bc9e320af832only as module-graph bookkeeping, because the new gin requires a newer framework. Thereplacedirective still pins the framework code compiled and tested here tov1.18.1-0.20260925125002-93850001fe6f(there is a matching comment above thatreplaceline ingo.mod). This is not a framework upgrade. The directgo.opentelemetry.io/otel*andgoogle.golang.org/grpcbumps are MVS-forced by gin/fiber's owngo.mod;go.sumis regenerated andgo mod tidy -diffis empty. Verified withgo test ./tests/feature -run '^TestViewTestSuite$' -v(gin) PASS,go test ./tests/feature -run 'TestFiberDriver/TestRender_' -v(fiber) PASS,gofmt -l routes testsclean, andgo build ./...OK.