GHSA-VH5J-5FHQ-9XWG
Vulnerability from github – Published: 2025-06-27 22:06 – Updated: 2025-06-30 12:53Hi 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.' });
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 8.1.2"
},
"package": {
"ecosystem": "npm",
"name": "taylored"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "8.1.3"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [],
"database_specific": {
"cwe_ids": [
"CWE-362"
],
"github_reviewed": true,
"github_reviewed_at": "2025-06-27T22:06:48Z",
"nvd_published_at": null,
"severity": "LOW"
},
"details": "Hi team,\n\nI 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.\n\n### Summary\nThe /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.\n\n### Details\n\nThe handler executes (step 1):\n\n```\nSELECT id, token_used_at FROM purchases WHERE patch_id = ? AND purchase_token = ? AND status = \u0027COMPLETED\u0027\n```\n\nIf token_used_at IS NULL, the request passes the check (step 2): \n```\n if (row.token_used_at) {\n return res.status(403).json({ error: \"Purchase token has already been used.\" });\n }\n```\n\n\nThe handler finally runs (step 3):\n\n```\nUPDATE purchases SET token_used_at = CURRENT_TIMESTAMP WHERE id = ?\n```\n\n\nWhen 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.\n\n### PoC\nTo perform this attack, you need to send two requests at the exact same time. \n\n### Impact\nAn 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.\n\n\n### Remediation\n\nReplace the read-then-write sequence with a single atomic statement that both validates and consumes the token while SQLite holds the write lock:\n\n```\nconst row = db.prepare(`\n UPDATE purchases\n SET token_used_at = CURRENT_TIMESTAMP\n WHERE patch_id = ?\n AND purchase_token = ?\n AND status = \u0027COMPLETED\u0027\n AND token_used_at IS NULL\n RETURNING id;\n`).get(patchId, token);\n\nif (!row) return res.status(403).json({ error: \u0027Invalid or already-used token.\u0027 });\n```",
"id": "GHSA-vh5j-5fhq-9xwg",
"modified": "2025-06-30T12:53:28Z",
"published": "2025-06-27T22:06:48Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/tailot/taylored/security/advisories/GHSA-vh5j-5fhq-9xwg"
},
{
"type": "WEB",
"url": "https://github.com/tailot/taylored/commit/fdf67a6fba0deae30912905a79fb5a9e83751a79"
},
{
"type": "PACKAGE",
"url": "https://github.com/tailot/taylored"
}
],
"schema_version": "1.4.0",
"severity": [],
"summary": "Taylor has race condition in /get-patch that allows purchase token replay"
}
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.