Summary
Use of this library in a security-critical context may result in leaking sensitive information, if used to process sensitive fields.
Details
OpenBao (and presumably HashiCorp Vault) have surfaced error messages from mapstructure
as follows:
https://github.com/openbao/openbao/blob/98c3a59c040efca724353ca46ca79bd5cdbab920/sdk/framework/field_data.go#L43-L50
_, _, err := d.getPrimitive(field, schema)
if err != nil {
return fmt.Errorf("error converting input for field %q: %w", field, err)
}
where this calls mapstructure.WeakDecode(...)
: https://github.com/openbao/openbao/blob/98c3a59c040efca724353ca46ca79bd5cdbab920/sdk/framework/field_data.go#L181-L193
func (d *FieldData) getPrimitive(k string, schema *FieldSchema) (interface{}, bool, error) {
raw, ok := d.Raw[k]
if !ok {
return nil, false, nil
}
switch t := schema.Type; t {
case TypeBool:
var result bool
if err := mapstructure.WeakDecode(raw, &result); err != nil {
return nil, false, err
}
return result, true, nil
Notably, WeakDecode(...)
eventually calls one of the decode helpers, which surfaces the original value:
|
if !converted { |
|
return fmt.Errorf( |
|
"'%s' expected type '%s', got unconvertible type '%s', value: '%v'", |
|
name, val.Type(), dataVal.Type(), data) |
|
} |
|
|
|
return nil |
|
} |
|
default: |
|
return fmt.Errorf( |
|
"'%s' expected type '%s', got unconvertible type '%s', value: '%v'", |
|
name, val.Type(), dataVal.Type(), data) |
|
} |
|
default: |
|
return fmt.Errorf( |
|
"'%s' expected type '%s', got unconvertible type '%s', value: '%v'", |
|
name, val.Type(), dataVal.Type(), data) |
|
} |
& more.
PoC
To reproduce with OpenBao:
$ podman run -p 8300:8300 openbao/openbao:latest server -dev -dev-root-token-id=root -dev-listen-address=0.0.0.0:8300
and in a new tab:
$ BAO_TOKEN=root BAO_ADDR=http://localhost:8300 bao auth enable userpass
Success! Enabled userpass auth method at: userpass/
$ curl -X PUT -H "X-Vault-Request: true" -H "X-Vault-Token: root" -d '{"password":{"asdf":"my-sensitive-value"}}' "http://localhost:8300/v1/auth/userpass/users/adsf"
{"errors":["error converting input for field \"password\": '' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[asdf:my-sensitive-value]'"]}
Impact
This is an information disclosure bug with little mitigation. See https://discuss.hashicorp.com/t/hcsec-2025-09-vault-may-expose-sensitive-information-in-error-logs-when-processing-malformed-data-with-the-kv-v2-plugin/74717 for a previous version. That version was fixed, but this is in the second part of that error message (starting at '' expected a map, got 'string'
-- when the field type is string
and a map
is provided, we see the above information leak -- the previous example had a map
type field with a string
value provided).
This was rated 4.5 Medium by HashiCorp in the past iteration.
Summary
Use of this library in a security-critical context may result in leaking sensitive information, if used to process sensitive fields.
Details
OpenBao (and presumably HashiCorp Vault) have surfaced error messages from
mapstructure
as follows:https://github.com/openbao/openbao/blob/98c3a59c040efca724353ca46ca79bd5cdbab920/sdk/framework/field_data.go#L43-L50
where this calls
mapstructure.WeakDecode(...)
: https://github.com/openbao/openbao/blob/98c3a59c040efca724353ca46ca79bd5cdbab920/sdk/framework/field_data.go#L181-L193Notably,
WeakDecode(...)
eventually calls one of the decode helpers, which surfaces the original value:mapstructure/mapstructure.go
Lines 679 to 686 in 1a66224
mapstructure/mapstructure.go
Lines 726 to 730 in 1a66224
mapstructure/mapstructure.go
Lines 783 to 787 in 1a66224
& more.
PoC
To reproduce with OpenBao:
and in a new tab:
Impact
This is an information disclosure bug with little mitigation. See https://discuss.hashicorp.com/t/hcsec-2025-09-vault-may-expose-sensitive-information-in-error-logs-when-processing-malformed-data-with-the-kv-v2-plugin/74717 for a previous version. That version was fixed, but this is in the second part of that error message (starting at
'' expected a map, got 'string'
-- when the field type isstring
and amap
is provided, we see the above information leak -- the previous example had amap
type field with astring
value provided).This was rated 4.5 Medium by HashiCorp in the past iteration.