Skip to content

Commit da0d6c1

Browse files
committed
feat: add auditReferrer flag and sanitize function for improved audit logging
1 parent 53ae1ab commit da0d6c1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

ui/cli/main.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var fullRestore bool // Flag for the restore command
5050
var password string // Flag for rotate-key password
5151
var verbose bool
5252
var showVersionFlag bool
53+
var auditReferrer string
5354

5455
// TODO should be moved to project root
5556
var appConfig config.Config
@@ -151,9 +152,19 @@ func setupDefaultServices(cmd *cobra.Command, args []string) error {
151152
// Start background session reaper
152153
core.StartSessionReaper()
153154

155+
core.SetAuditContext("cli", sanitizeAuditReferrer(auditReferrer))
156+
154157
return nil
155158
}
156159

160+
func sanitizeAuditReferrer(referrer string) string {
161+
referrer = strings.TrimSpace(referrer)
162+
if len(referrer) > 255 {
163+
referrer = referrer[:255]
164+
}
165+
return referrer
166+
}
167+
157168
// Execute runs the CLI entrypoint. The cmd/keymaster main package should
158169
// call this function and handle process exit.
159170
func Execute() error {
@@ -251,6 +262,7 @@ Running without a subcommand will launch the interactive TUI.`,
251262
return setupDefaultServices(cmd, args)
252263
},
253264
Run: func(cmd *cobra.Command, args []string) {
265+
core.SetAuditContext("tui", sanitizeAuditReferrer(auditReferrer))
254266
// The database is already initialized by PersistentPreRunE.
255267
// i18n is also initialized, so we can just run the TUI.
256268
// The store adapter is created for side-effects during setup,
@@ -287,6 +299,7 @@ Running without a subcommand will launch the interactive TUI.`,
287299
// Define flags
288300
cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output (sets -v for DB logs)")
289301
cmd.PersistentFlags().BoolVarP(&showVersionFlag, "version", "V", false, "Print version and exit")
302+
cmd.PersistentFlags().StringVar(&auditReferrer, "referrer", "", "Optional referrer metadata included in audit logs")
290303
cmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
291304
cmd.PersistentFlags().String("language", "en", `TUI language ("en", "de")`)
292305
applyDefaultFlags(cmd)

0 commit comments

Comments
 (0)