# GHSA-vh5j-5fhq-9xwg: Taylor has race condition in /get-patch that allows purchase token replay

> An attacker with a valid purchase token can exploit a race condition to replay the token and obtain multiple copies of paid patches.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 27 Jun 2025

## What is GHSA-vh5j-5fhq-9xwg?

GHSA-vh5j-5fhq-9xwg is a vulnerability in taylored, published on 27 Jun 2025. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

Hi team,

I was looking at the recent fix and you limited the exploitability of race conditions but unfortunately it is still possible to exploit the issue since two requests happening at the exact same time will still go through. You should be able to completely fix the race conditions by leveraging SQLITE write lock and just send one query.

### Summary
The /get-patch endpoint processes a purchase in two separate database queries: a SELECT that verifies the token is unused, followed by an UPDATE that marks the token as used. Because SQLite only guards each statement, a malicious actor can issue two requests at the exact same moment and have both SELECT statements succeed before either UPDATE runs.

### Details

The handler executes (step 1):

```
SELECT id, token_used_at FROM purchases WHERE patch_id = ? AND purchase_token = ? AND status = 'COMPLETED'
```

If token_used_at IS NULL, the request passes the check (step 2): 
```
        if (row.token_used_at) {
            return res.status(403).json({ error: "Purchase token has already been used." });
        }
```

The handler finally runs (step 3):

```
UPDATE purchases SET token_used_at = CURRENT_TIMESTAMP WHERE id = ?
```

When two requests arrive at the same time, they both finish step 1 while the row is still unused. SQLite serializes writers only per statement, so each request believes it has exclusive access. Both decrypt and return the patch, and both UPDATE statements succeed.

### PoC
To perform this attack, you need to send two requests at the exact same time. 

### Impact
An attacker who possesses a valid purchase token can replay it and receive multiple copies of the paid patch, or distribute one copy while still keeping their own. This results in revenue loss and undermines license enforcement.

### Remediation

Replace the read-then-write sequence with a single atomic statement that both validates and consumes the token while SQLite holds the write lock:

```
const row = db.prepare(`
  UPDATE purchases
     SET token_used_at = CURRENT_TIMESTAMP
   WHERE patch_id       = ?
     AND purchase_token = ?
     AND status         = 'COMPLETED'
     AND token_used_at IS NULL
  RETURNING id;
`).get(patchId, token);

if (!row) return res.status(403).json({ error: 'Invalid or already-used token.' });
```

## Which versions are affected by GHSA-vh5j-5fhq-9xwg?

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `taylored` | npm | All versions | 8.1.3 |
| `taylored` | npm | All versions | 8.1.3 |

## How do I fix GHSA-vh5j-5fhq-9xwg?

Upgrade taylored to 8.1.3 or later.

## Is GHSA-vh5j-5fhq-9xwg being exploited?

There is no known exploitation of GHSA-vh5j-5fhq-9xwg in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-vh5j-5fhq-9xwg and fix it if it is affected.

What it is: GHSA-vh5j-5fhq-9xwg is a vulnerability in taylored, published on 27 Jun 2025. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-vh5j-5fhq-9xwg in the wild and no public exploit code.

Affected packages and fixed versions:
- taylored (npm): affected all versions; fixed in 8.1.3
- taylored (npm): affected all versions; fixed in 8.1.3

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-vh5j-5fhq-9xwg/ (Markdown: https://insights.sbomify.com/GHSA-vh5j-5fhq-9xwg/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-vh5j-5fhq-9xwg

---
From sbomify Insights: https://insights.sbomify.com/GHSA-vh5j-5fhq-9xwg/
Summaries are generated and may contain mistakes; the official description above is the record.
