Skip to content

Security: Critical Safety Bypass via Stacked Queries #1

Description

@nkar123412-hub

I have discovered a critical vulnerability in the safety mechanism of Berth that allows bypassing the 'read-only' and 'write' modes.

The current safety check in safety.py uses regular expressions to detect the type of SQL statement by checking only the start of the query (e.g., ^\s*SELECT\b).

Vulnerability: Stacked Queries
An attacker can execute destructive operations (like DROP TABLE) even in read-only mode by prepending a valid SELECT statement.
Example: 'SELECT 1; DROP TABLE users;'

Since the server only validates the start of the query, it will identify this as a 'SELECT' statement and allow it. If the underlying database driver and database (e.g., PostgreSQL, MySQL) support stacked queries, the destructive command will be executed.

Impact:
Full database compromise, including unauthorized data modification and deletion.

Recommendation:

  1. Disable stacked queries at the database driver level.
  2. Use a proper SQL parser to analyze all statements in a query instead of relying on start-of-string regex.
  3. Implement strict role-based access control (RBAC) at the database level rather than relying on application-level filters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions