# GHSA-3hpf-ff72-j67p: shared_preferences_android vulnerability

> An attacker with local file write access can overwrite preference files to trigger arbitrary code execution via unsafe deserialization in the shared_preferences_android library.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 6 Dec 2024

## What is GHSA-3hpf-ff72-j67p?

GHSA-3hpf-ff72-j67p is an unsafe deserialization vulnerability in shared_preferences_android, published on 6 Dec 2024. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

### Impact
Due to some data types not being natively representable for the available storage options, shared_preferences_android serializes and deserializes special string prefixes to store these unrepresentable data types. This allows arbitrary classes to be deserialized leading to arbitrary code execution.

As a result, Files containing the preferences can be overwritten with a malicious one with a deserialization payload that triggers as soon as the data is loaded from the disk.

### Patches
2.3.4

### Workarounds
Update to the latest version of shared_preferences_android that contains the changes to address this vulnerability.

### References
TBD

### For more information
See [our community page](https://dart.dev/community) to find ways to contact the team.

### Thanks
Thank you so much to Oskar Zeino-Mahmalat from sonarsource for finding and reporting this issue!

## Which versions are affected by GHSA-3hpf-ff72-j67p?

2 open source packages ship an affected version, including shared_preferences_android.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `shared_preferences_android` | Pub | From 2.3.3 | 2.3.4 |
| `shared_preferences_android` | Pub | From 2.3.3 | 2.3.4 |

## How do I fix GHSA-3hpf-ff72-j67p?

Upgrade shared_preferences_android to 2.3.4 or later.

## Is GHSA-3hpf-ff72-j67p being exploited?

There is no known exploitation of GHSA-3hpf-ff72-j67p in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-3hpf-ff72-j67p and fix it if it is affected.

What it is: GHSA-3hpf-ff72-j67p is an unsafe deserialization vulnerability in shared_preferences_android, published on 6 Dec 2024. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-3hpf-ff72-j67p in the wild and no public exploit code.

Affected packages and fixed versions:
- shared_preferences_android (Pub): affected from 2.3.3; fixed in 2.3.4
- shared_preferences_android (Pub): affected from 2.3.3; fixed in 2.3.4

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-3hpf-ff72-j67p/ (Markdown: https://insights.sbomify.com/GHSA-3hpf-ff72-j67p/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-3hpf-ff72-j67p

---
From sbomify Insights: https://insights.sbomify.com/GHSA-3hpf-ff72-j67p/
Summaries are generated and may contain mistakes; the official description above is the record.
