Skip to content

Commit 03fce8f

Browse files
Fixing issue #35530: Password Leak in Log Messages (#35584)
The Gitea codebase was logging `Elasticsearch` and `Meilisearch` connection strings directly to log files without sanitizing them. Since connection strings often contain credentials in the format `protocol://username:password@host:port`, this resulted in passwords being exposed in plain text in log output. Fix: - wrapped all instances of setting.Indexer.RepoConnStr and setting.Indexer.IssueConnStr with the `util.SanitizeCredentialURLs()` function before logging them. Fixes: #35530 Co-authored-by: Lunny Xiao <[email protected]>
1 parent 69f5ee9 commit 03fce8f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

modules/indexer/code/indexer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"code.gitea.io/gitea/modules/process"
2323
"code.gitea.io/gitea/modules/queue"
2424
"code.gitea.io/gitea/modules/setting"
25+
"code.gitea.io/gitea/modules/util"
2526
)
2627

2728
var (
@@ -166,12 +167,12 @@ func Init() {
166167
log.Fatal("PID: %d Unable to initialize the bleve Repository Indexer at path: %s Error: %v", os.Getpid(), setting.Indexer.RepoPath, err)
167168
}
168169
case "elasticsearch":
169-
log.Info("PID: %d Initializing Repository Indexer at: %s", os.Getpid(), setting.Indexer.RepoConnStr)
170+
log.Info("PID: %d Initializing Repository Indexer at: %s", os.Getpid(), util.SanitizeCredentialURLs(setting.Indexer.RepoConnStr))
170171
defer func() {
171172
if err := recover(); err != nil {
172173
log.Error("PANIC whilst initializing repository indexer: %v\nStacktrace: %s", err, log.Stack(2))
173174
log.Error("The indexer files are likely corrupted and may need to be deleted")
174-
log.Error("You can completely remove the \"%s\" index to make Gitea recreate the indexes", setting.Indexer.RepoConnStr)
175+
log.Error("You can completely remove the \"%s\" index to make Gitea recreate the indexes", util.SanitizeCredentialURLs(setting.Indexer.RepoConnStr))
175176
}
176177
}()
177178

@@ -181,7 +182,7 @@ func Init() {
181182
cancel()
182183
(*globalIndexer.Load()).Close()
183184
close(waitChannel)
184-
log.Fatal("PID: %d Unable to initialize the elasticsearch Repository Indexer connstr: %s Error: %v", os.Getpid(), setting.Indexer.RepoConnStr, err)
185+
log.Fatal("PID: %d Unable to initialize the elasticsearch Repository Indexer connstr: %s Error: %v", os.Getpid(), util.SanitizeCredentialURLs(setting.Indexer.RepoConnStr), err)
185186
}
186187

187188
default:

modules/indexer/issues/indexer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/process"
2626
"code.gitea.io/gitea/modules/queue"
2727
"code.gitea.io/gitea/modules/setting"
28+
"code.gitea.io/gitea/modules/util"
2829
)
2930

3031
// IndexerMetadata is used to send data to the queue, so it contains only the ids.
@@ -100,15 +101,15 @@ func InitIssueIndexer(syncReindex bool) {
100101
issueIndexer = elasticsearch.NewIndexer(setting.Indexer.IssueConnStr, setting.Indexer.IssueIndexerName)
101102
existed, err = issueIndexer.Init(ctx)
102103
if err != nil {
103-
log.Fatal("Unable to issueIndexer.Init with connection %s Error: %v", setting.Indexer.IssueConnStr, err)
104+
log.Fatal("Unable to issueIndexer.Init with connection %s Error: %v", util.SanitizeCredentialURLs(setting.Indexer.IssueConnStr), err)
104105
}
105106
case "db":
106107
issueIndexer = db.GetIndexer()
107108
case "meilisearch":
108109
issueIndexer = meilisearch.NewIndexer(setting.Indexer.IssueConnStr, setting.Indexer.IssueConnAuth, setting.Indexer.IssueIndexerName)
109110
existed, err = issueIndexer.Init(ctx)
110111
if err != nil {
111-
log.Fatal("Unable to issueIndexer.Init with connection %s Error: %v", setting.Indexer.IssueConnStr, err)
112+
log.Fatal("Unable to issueIndexer.Init with connection %s Error: %v", util.SanitizeCredentialURLs(setting.Indexer.IssueConnStr), err)
112113
}
113114
default:
114115
log.Fatal("Unknown issue indexer type: %s", setting.Indexer.IssueType)

0 commit comments

Comments
 (0)