harbor-labs / checkout-api #1842

A finding you can patch.

Explore a sample review. Select a file, inspect the issue, and compare the suggested fix.

Review your code
Sample data3 findings3 filesA fix and test for every finding
Pull Request #1842 · harbor-labs/checkout-api3 findings

Untrusted user_id is concatenated into a raw SQL string. An attacker can append OR 1=1 or UNION SELECT and read other customers' orders.

Flagged code
query = f"SELECT * FROM orders WHERE user_id = '{user_id}' AND status = 'active'"
cursor.execute(query)
Suggested fix
from sqlalchemy import text

stmt = text("SELECT * FROM orders WHERE user_id = :user_id AND status = 'active'")
cursor.execute(stmt, {"user_id": user_id})
Test stub
def test_get_user_orders_rejects_injection(client):
    response = client.get("/orders", params={"user_id": "1' OR '1'='1"})
    assert response.status_code in {400, 404}

merged94% confidence