Skip to content

Unescaped query parameter in query-database.php #129

Description

@CoachBirgit

Description

The query-database ability passes a user-constructed $query variable directly into $wpdb->get_results() without preparation or escaping.

Affected lines

  • Line 157: $wpdb->get_results() with unescaped $query (assigned at line 154)
  • Same line: no caching around the query

Action needed

This ability accepts SQL from the AI, which is already a sensitive operation. At minimum:

  1. Validate that the query is read-only (starts with SELECT, does not contain INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE)
  2. Use $wpdb->prepare() where possible
  3. Add caching or document why it's skipped
  4. Consider a query length limit and timeout

PHPCS rules

  • WordPress.DB.DirectDatabaseQuery.DirectQuery (WARNING)
  • WordPress.DB.DirectDatabaseQuery.NoCaching (WARNING)
  • PluginCheck.Security.DirectDB.UnescapedDBParameter (WARNING)

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions