fix(dark-tariff): patch SQLi, weak calculation_id, and ZKP challenge bias
This commit is contained in:
1 parent
1857506f60
commit
58bdfcb829
5 files changed
+312
-16
No files matched your search
@@ -1,9 +1,7 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import secrets
|
||||
|
||||
import psycopg
|
||||
from argon2.low_level import Type, hash_secret_raw
|
||||
from psycopg.types.json import Jsonb
|
||||
|
||||
from backend.app.db import connection
|
||||
@@ -19,10 +17,7 @@ async def reading_public(reading_id):
|
||||
return await call("select billing.reading_public(%s::bigint)", (reading_id,))
|
||||
|
||||
def calculation_key(reading_id):
|
||||
value = f"{reading_id}|{secrets.randbelow(10000):04d}".encode("ascii")
|
||||
key = hash_secret_raw(value, bytes(16), time_cost=1, memory_cost=8192,
|
||||
parallelism=1, hash_len=32, type=Type.ID, version=19)
|
||||
return base64.b64encode(key).decode("ascii")
|
||||
return base64.b64encode(secrets.token_bytes(32)).decode("ascii")
|
||||
|
||||
async def add_reading(serial, kind, metrics):
|
||||
try:
|
||||
@@ -33,7 +28,7 @@ async def add_reading(serial, kind, metrics):
|
||||
(serial, kind, Jsonb(metrics)),
|
||||
)
|
||||
reading = (await cursor.fetchone())[0]
|
||||
key = await asyncio.to_thread(calculation_key, reading["id"])
|
||||
key = calculation_key(reading["id"])
|
||||
cursor = await db.execute(
|
||||
"select billing.receipt_issue(r, %s::text)"
|
||||
" from billing.reading r where r.id = %s::bigint",
|
||||
|
||||
Reference in new issue
Block a user