logger: dotenvダンプの秘密漏洩・panic・データ競合を修正 (#16)#22
Merged
Conversation
## 理由 GETENV_DUMP_MODE=dotenv の経路に、デフォルト値(秘密になり得る)の出力、 書き込みエラー時の panic、Logger.w のデータ競合、並行 Write による出力破損が 存在していた(#16)。ライブラリがロギングの副作用で秘密を漏らしたりホストを クラッシュさせたりすべきではないため修正する。 ## 修正点 - デフォルト値出力を既定でマスク(KEY=)し、Logger.DumpValues(true) で 明示的に opt-in したときのみ実値を出力するように変更(secure by default) - Dump の書き込みエラーを panic からベストエフォートの log 出力に変更 - Logger.w を sync.Mutex で保護し、SetWriter とのデータ競合を解消 - 1 レコードを単一 Write に集約し、並行ダンプ時の行の交錯を防止 - logger_test.go を追加(マスク/opt-in/panic 回避/並行 -race を検証) - README(en/jp)に dotenv ダンプ機能と DumpValues を追記
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.
概要
logger.goの dotenv ダンプ経路(GETENV_DUMP_MODE=dotenv)に集中していた、秘密漏洩フットガン・panic・データ競合・出力破損をまとめて修正します。Closes #16
背景
セキュリティ監査(敵対的検証済み)で、以下が検出されていました(いずれも opt-in なデバッグ経路ゲートのため深刻度 low ですが、ライブラリがロギング副作用で秘密を漏らしたりホストをクラッシュさせるべきではありません)。
panicし全アクセサに伝播 → ホストプロセス DoSLogger.wが無ロックでSetWriterとデータ競合Writeに分割しており並行時に行が交錯(監査で 400 行中 153 行破損を実測)変更点
KEY=)し、Logger.DumpValues(true)で明示的に opt-in したときのみ実値を出力(環境変数からtime.Durationを取得する #1 / test追加 #2)Dumpの書き込みエラーをpanicからベストエフォートのlog.Printfに変更(duration取得する #3)Logger.w/dumpValuesをsync.Mutexで保護(add readme #4)bytes.Bufferで組み立て単一Writeに集約(time.ParseDuration使う #5)logger_test.goを追加:マスク既定 / opt-in / スライス / panic 回避 / 並行(-race・行の非交錯)を検証DumpValuesを追記(従来は未記載)補足(スコープ外)
os.Getenvを毎回読む):example.goが実行時にGETENV_DUMP_MODEをセットして使う動作に依存するため、init キャッシュ化は破壊的。info かつ実害なし(Go 1.21 では O(1))のため据え置き。挙動変更(破壊的の可能性)
GETENV_DUMP_MODE=dotenvの出力がKEY=<デフォルト値>→KEY=(マスク)に変わります。従来どおり値を出したい場合はgetenv.Logger.DumpValues(true)を呼んでください。dotenv ダンプは README 未記載のデバッグ機能のため影響は限定的と判断しています。テスト
go build ./...✅go vet ./...✅go test ./...✅go test -race ./...✅🤖 Generated with Claude Code