file: ensure parent directory exists in Save; bump Go to 1.26 and CI actions#177
Merged
Conversation
fileStore.Save writes the session file directly with os.WriteFile, but
the two-level parent directory (<root>/<sid[0]>/<sid[1]>/) is only
created lazily inside Read. When Save is called for a session ID whose
parent directory does not yet exist, it fails with:
open <root>/i/3/i3qn0rl89bvr19oi: no such file or directory
This is reachable via the documented RegenerateID flow: after login,
applications commonly regenerate the session ID to defend against
session fixation. BaseSession.RegenerateID mints a fresh SID and mutates
s.sid in place without touching the store, so the next Save writes to a
path whose parent directory was never created.
Fix by calling os.MkdirAll(filepath.Dir(filename), 0700) before
os.WriteFile, mirroring the same pattern already present in Read.
- go.mod: go 1.25.0 -> 1.26.0 - workflow matrix: 1.24.x -> 1.26.x - actions/checkout@v4 -> v6 - actions/setup-go@v5 -> v6 - golangci/golangci-lint-action@v7 -> v9
Fixes a SQLITE_BUSY panic in TestSQLiteStore that surfaces under Go 1.26 with v1.50.0. v1.51.0 resolves it without other changes.
a85f829 to
c3e0568
Compare
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
Three changes bundled per request:
1. Bug fix:
fileStore.Savefails when parent directory does not existfileStore.Savewrites the session file directly withos.WriteFile, but the two-level parent directory (<root>/<sid[0]>/<sid[1]>/) is only created lazily insideRead. WhenSaveis called for a session ID whose parent directory does not yet exist, it fails with:This is reachable via the documented
RegenerateIDflow: after login, applications commonly regenerate the session ID to defend against session fixation.BaseSession.RegenerateIDmints a fresh SID and mutatess.sidin place without touching the store, so the nextSavewrites to a path whose parent directory was never created.Fix: call
os.MkdirAll(filepath.Dir(filename), 0700)beforeos.WriteFileinfileStore.Save, mirroring the same pattern already present inRead(file.go:71). Mode0700matchesReadand the0600files it contains.2. Chore: bump Go to 1.26 and CI actions to latest
go.mod:go 1.25.0→go 1.26.01.24.x→1.26.xactions/checkout@v4→v6actions/setup-go@v5→v6golangci/golangci-lint-action@v7→v93. Bump
modernc.org/sqliteto v1.51.0Under Go 1.26,
TestSQLiteStorepanics withSQLITE_BUSYonv1.50.0.v1.51.0resolves it cleanly.Test plan
go test ./...passes forgithub.com/flamego/sessionon Go 1.26go test ./sqlitepasses on Go 1.26 withmodernc.org/sqlite v1.51.0fileStore.Savefix resolves theopen ... no such file or directoryerror in a downstream app that callsRegenerateIDafter login