Skip to content

Commit ce11c90

Browse files
cheddarfoxclaude
andcommitted
fix(security): wrap raw SQL with text() in billing modules [REN-68]
Remediate OWASP A03 (Injection) in legacy billing code: - cron_monthly.py: wrap raw SELECT with sqlalchemy.text() - invoice_builder.py: wrap parameterized SELECT with sqlalchemy.text() - All 4 billing files: add TODO(REN-87) for legacy db import migration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 02adc42 commit ce11c90

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎core/billing/invoice/cron_monthly.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import os
33

44
import postmarker
5-
from db import async_session
5+
from db import async_session # TODO(REN-87): Migrate from legacy db module to core.database
66
from invoice_builder import PERIOD, build
7+
from sqlalchemy import text
78

89
client = postmarker.PostmarkClient(server_token=os.environ["POSTMARK_KEY"])
910

1011

1112
async def main():
1213
async with async_session() as s:
13-
rows = await s.execute("SELECT id,email FROM creators")
14+
rows = await s.execute(text("SELECT id,email FROM creators"))
1415
for r in rows:
1516
url, total = await build(r.id)
1617
client.emails.send(

‎core/billing/invoice/invoice_builder.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import jinja2
55
import weasyprint
66
from boto3 import client as s3
7-
from db import async_session
7+
from db import async_session # TODO(REN-87): Migrate from legacy db module to core.database
8+
from sqlalchemy import text
89

910
S3 = s3(
1011
"s3",
@@ -19,7 +20,7 @@
1920
async def build(account_id: str):
2021
async with async_session() as s:
2122
rows = await s.execute(
22-
"""SELECT created_at, delta_usd FROM ledger_entries WHERE account_id=:a AND date_trunc('month', created_at)=date_trunc('month', now()-interval '1 month')""",
23+
text("SELECT created_at, delta_usd FROM ledger_entries WHERE account_id=:a AND date_trunc('month', created_at)=date_trunc('month', now()-interval '1 month')"),
2324
{"a": account_id},
2425
)
2526
items = [

‎core/billing/stripe/ledger/credit.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from db import Ledger, async_session
1+
from db import Ledger, async_session # TODO(REN-87): Migrate from legacy db module to core.database
22

33

44
async def credit(creator_id: str, amount: float):

‎core/billing/webhook.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from db import Ledger, UsageEvent, async_session
1+
from db import ( # TODO(REN-87): Migrate from legacy db module to core.database
2+
Ledger,
3+
UsageEvent,
4+
async_session,
5+
)
26
from fastapi import APIRouter, Request
37
from sqlalchemy import func, select
48

0 commit comments

Comments
 (0)