Skip to content

BUG-041: f-string in te_loader.py execute() — SQL injection risk #10

Closed

Description

@amar-python

Summary

_cleanup_prior_registry_entries in api/services/te_loader.py line 99
uses an f-string inside execute(), which is prohibited by the AST security
test.

Failing test

tests/test_api.py::TableNameGuards::test_identifiers_are_never_string_formatted

Error: execute() called with an f-string at ['te_loader.py:99']

Root cause

The function was extracted from an inline block during the sync from
PostgreDataMigrationApp. The original used psycopg2.sql.Identifier; the
extraction accidentally used an f-string instead.

Fix

Replace line 99 in api/services/te_loader.py:

Before:
cur.execute(f"DROP TABLE IF EXISTS {table_name}")

After:
from psycopg2 import sql as _sql
cur.execute(
_sql.SQL("DROP TABLE IF EXISTS {}").format(
_sql.Identifier(*table_name.split("."))
if "." in table_name
else _sql.Identifier(table_name)
)
)

Files affected

  • api/services/te_loader.py line 99

Activity

  1. amar-python commented on Aug 11, 2026

    @amar-python
    OwnerAuthor

    Fixed — _cleanup_prior_registry_entries extracted with psycopg2.sql.Identifier, no f-strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions