T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/service_layer/db_bridge.py:674- Finding
Table Allowlist Bypass Through Incomplete SQL Object Extraction
- Content
View full analysis
str: m = re.search( r"(?:FROM|UPDATE|INSERT\s+INTO|INTO|DELETE\s+FROM)\s+(\w+)", sql, re.IGNORECASE ) ``` ### Technical Analysis The bridge attempts to enforce a table allowlist by extracting one table name from the supplied SQL statement. The regular expression returns only the first matching table reference. The complete SQL statement is subsequently passed to the database without validating all referenced tables. SQL may reference multiple objects through joins, subqueries, common table expressions, or set operations. For example, a query can begin with an allowed table and subsequently access a blocked table: ```sql SELECT permitted.id, restricted.secret FROM permitted JOIN restricted ON restricted.id = permitted.id ``` A similar bypass may be constructed with `UNION` or a nested subquery. Because `_extract_table()` identifies `permitted` as the first table, the bridge authorizes the statement even though it also accesses `restricted`. The regular expression is not a security-grade SQL parser and cannot reliably account for comments, quoted identifiers, dialect-specific syntax, common table expressions, or multiple statements. The authorization dec ...[truncated 1297 chars]- Remediation
View remediation
