mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6189] [MERGED] fix(web): fallback to default secret when database setting is empty #6151
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6151
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6189
Author: @CaMeDoZa
Created: 8/8/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @MHSanaei
Base:
main← Head:fix/empty-secret-fallback📝 Commits (4)
ff8dfe8fix(web): fallback to default secret when database setting is empty5f31383Merge branch 'main' into fix/empty-secret-fallback42c90a3style(web): format setting_security_test.go with gofumpt20c753eMerge branch 'main' into fix/empty-secret-fallback📊 Changes
2 files changed (+32 additions, -4 deletions)
View changed files
📝
internal/web/service/setting.go(+7 -4)📝
internal/web/service/setting_security_test.go(+25 -0)📄 Description
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.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.