# GHSA-fv92-fjc5-jj9h: mapstructure May Leak Sensitive Information in Logs When Processing Malformed Data

> The mapstructure library may leak sensitive input values in error logs when processing malformed data, potentially exposing secrets to attackers with log access.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** An administrator
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 27 Jun 2025
- **Also known as:** GO-2025-3787

## What is GHSA-fv92-fjc5-jj9h?

GHSA-fv92-fjc5-jj9h is a vulnerability in github.com/go-viper/mapstructure, published on 27 Jun 2025. An attacker needs administrator access to exploit it, with no action from the victim.

### Official description

### 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

```go
			_, _, 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

```go

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:

https://github.com/go-viper/mapstructure/blob/1a66224d5e54d8757f63bd66339cf764c3292c21/mapstructure.go#L679-L686

https://github.com/go-viper/mapstructure/blob/1a66224d5e54d8757f63bd66339cf764c3292c21/mapstructure.go#L726-L730

https://github.com/go-viper/mapstructure/blob/1a66224d5e54d8757f63bd66339cf764c3292c21/mapstructure.go#L783-L787

& 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.

## Which versions are affected by GHSA-fv92-fjc5-jj9h?

4 open source packages ship an affected version, including github.com/go-viper/mapstructure/v2 and github.com/go-viper/mapstructure.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/go-viper/mapstructure/v2` | Go | All versions | 2.3.0 |
| `github.com/go-viper/mapstructure/v2` | Go | All versions | 2.3.0 |
| `github.com/go-viper/mapstructure/v2` | Go | All versions | 2.3.0 |
| `github.com/go-viper/mapstructure` | Go | All versions | None |

## How do I fix GHSA-fv92-fjc5-jj9h?

Upgrade github.com/go-viper/mapstructure/v2 to 2.3.0 or later.

## Is GHSA-fv92-fjc5-jj9h being exploited?

There is no known exploitation of GHSA-fv92-fjc5-jj9h in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-fv92-fjc5-jj9h and fix it if it is affected.

What it is: GHSA-fv92-fjc5-jj9h is a vulnerability in github.com/go-viper/mapstructure, published on 27 Jun 2025. An attacker needs administrator access to exploit it, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-fv92-fjc5-jj9h in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/go-viper/mapstructure/v2 (Go): affected all versions; fixed in 2.3.0
- github.com/go-viper/mapstructure/v2 (Go): affected all versions; fixed in 2.3.0
- github.com/go-viper/mapstructure/v2 (Go): affected all versions; fixed in 2.3.0
- github.com/go-viper/mapstructure (Go): affected all versions; no fix listed

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-fv92-fjc5-jj9h/ (Markdown: https://insights.sbomify.com/GHSA-fv92-fjc5-jj9h/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-fv92-fjc5-jj9h

---
From sbomify Insights: https://insights.sbomify.com/GHSA-fv92-fjc5-jj9h/
Summaries are generated and may contain mistakes; the official description above is the record.
