fix(web): fallback to default secret when database setting is empty - #6189
Open
CaMeDoZa wants to merge 1 commit into
Open
fix(web): fallback to default secret when database setting is empty#6189CaMeDoZa wants to merge 1 commit into
CaMeDoZa wants to merge 1 commit into
Conversation
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
Fixes unhandled
HTTP 500 Internal Server Error("securecookie: hash key is not set") andHTTP 403 Forbiddenlogin failures by ensuringGetSecret()falls back to generating and persisting a default 32-byte secret when the databasesecretsetting is empty.Why
During database migrations, manual resets, or domain/SSL setup adjustments, if the
secretvalue in SQLitesettingsbecomes an empty string (""),GetSecret()returns empty bytes ([]byte("")). This causescookie.NewStoreinweb.goto be initialized with an invalid key, breakinggorilla/securecookiesession management and producing500errors on/csrf-tokenand403on/login.Type of change
Areas affected
How was this tested?
TestGetSecret_FallbacksOnEmptyDatabaseSettingininternal/web/service/setting_security_test.gothat verifiesGetSecret()generates and persists a 32-byte string when the databasesecretkey is empty.go test -v ./internal/web/service/ -run TestGetSecret_FallbacksOnEmptyDatabaseSetting(PASSED).secretsetting: verified/csrf-tokenreturns200 OKand session authentication completes successfully.Screenshots / recordings
N/A
Breaking changes
None
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.