Skip to content

Commit fa3bd66

Browse files
committed
fix(worker): store iv as hex string instead of raw bytes
The SavedPackageData.iv column is String(255), but the worker was writing the raw bytes returned by os.urandom(16). SQLAlchemy/psycopg2 serialize bytes-into-text as PostgreSQL's BYTEA literal "\x..." + hex, which then flowed straight to the client through /blob's JSON response. The frontend tried to use that as a hex IV, AES-CBC produced garbage, and the loading screen was stuck on "processing" forever. Fix: write iv.hex() at the worker. App's /blob handler now just returns row.iv as-is — the previous defensive bytes-to-hex check was masking the real bug. Existing rows written before this fix still carry the "\x..." prefix and need to be reprocessed (delete + POST /process).
1 parent 21cb538 commit fa3bd66

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/app.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,9 @@ def get_package_blob(package_id):
238238
if not row or not blob_storage.exists(package_id):
239239
return make_response('', 404)
240240

241-
iv_value = row.iv
242-
if isinstance(iv_value, (bytes, bytearray)):
243-
iv_value = iv_value.hex()
244-
245241
return jsonify({
246242
'url': blob_storage.presigned_url(package_id, ttl_seconds=ttl),
247-
'iv': iv_value,
243+
'iv': row.iv,
248244
'ttl': ttl,
249245
}), 200
250246

src/tasks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,12 @@ def _is_in_existing_event(t):
913913

914914
# Encrypted blob → S3 (clients fetch via presigned URL); only the iv
915915
# stays in Postgres so the API can hand it to the client for decryption.
916+
# Store iv as hex — the column is a String, so writing raw bytes lets
917+
# PostgreSQL serialize it as the BYTEA literal "\x..." which leaks
918+
# straight to the client.
916919
import blob_storage
917920
blob_storage.upload(package_id, data)
918-
session.add(SavedPackageData(package_id=package_id, iv=iv))
921+
session.add(SavedPackageData(package_id=package_id, iv=iv.hex()))
919922
session.commit()
920923

921924
print(f'SQLite serialization: {time.time() - start}')

0 commit comments

Comments
 (0)