fix: harden read-only target diagnostics
This commit is contained in:
+17
-1
@@ -535,7 +535,7 @@ func (a *Adapter) readSettings(ctx context.Context) (settings, error) {
|
||||
if result.HTTPAuthUser, err = a.getString(ctx, httpSchema, "authentication-user"); err != nil {
|
||||
return settings{}, err
|
||||
}
|
||||
if result.HTTPAuthPassword, err = a.getString(ctx, httpSchema, "authentication-password"); err != nil {
|
||||
if result.HTTPAuthPassword, err = a.getSensitiveString(ctx, httpSchema, "authentication-password"); err != nil {
|
||||
return settings{}, err
|
||||
}
|
||||
if result.HTTPSHost, err = a.getString(ctx, httpsSchema, "host"); err != nil {
|
||||
@@ -560,6 +560,22 @@ func (a *Adapter) getString(ctx context.Context, schema, key string) (string, er
|
||||
}
|
||||
return parseString(raw)
|
||||
}
|
||||
|
||||
// getSensitiveString deliberately suppresses both command error detail and raw
|
||||
// output. A password value is secret even when malformed, and command runners
|
||||
// are not trusted to keep that value out of their errors.
|
||||
func (a *Adapter) getSensitiveString(ctx context.Context, schema, key string) (string, error) {
|
||||
raw, err := a.run(ctx, "get", schema, key)
|
||||
if err != nil {
|
||||
return "", safeRedaction(fmt.Sprintf("get %s %s failed; sensitive output suppressed", schema, key), err)
|
||||
}
|
||||
value, err := parseString(strings.TrimSpace(raw))
|
||||
if err != nil {
|
||||
return "", errors.New("parse " + schema + " " + key + " failed; sensitive output suppressed")
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (a *Adapter) getInt(ctx context.Context, schema, key string) (int, error) {
|
||||
raw, err := a.get(ctx, schema, key)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user