Independent analysis by NHI Mgmt GroupSource article: depthfirst, “Narrow Grants, Wide Engines: Reaching Native Database Attack Surface from Minimal SQL Roles” (November 18, 2026)

TL;DR: Restrictive SQL grants still leave native database engine code reachable, and Oracle AI Database, PostgreSQL and MySQL all exposed paths where low-privilege or unauthenticated access could become arbitrary command execution, according to depthfirst. Database authorization narrows tables and schemas, but it does not contain memory-unsafe planner, parser and wire-protocol code.


At a glance

What this is: NHI Mgmt Group's analysis, drawing on depthfirst's blog post: Minimal SQL roles can still reach native engine code, and that exposure can collapse database privilege boundaries into remote code execution.

Why it matters: Database teams need to treat SQL authorization as only one layer of containment, because session features and native engine paths can still turn limited roles into host-level compromise.


Context

A database role is not the same thing as a safe execution boundary. SQL grants mainly govern access to schemas, tables and logical objects, while the engine underneath still executes planner rewrites, parser logic and memory-unsafe native code for permitted statements.

That gap matters because session-scoped features such as temporary schemas, temporary tables and prepared statements can give a low-privilege account enough building blocks to reach dangerous code paths. In other words, the attack surface is shaped as much by engine behaviour as by database credential and access security design.

The starting position is not unusual. Many production databases are deployed under least-privilege assumptions that work well for data access, but do not fully account for how much native code remains reachable from a valid session.


Key questions

Q: How should teams limit attack surface in database roles?

A: Limit database roles to the smallest set of DDL, DML and object privileges needed, and avoid granting access to temporary objects unless a workload truly requires them. Temporary tables, temp schemas and similar scratch space can widen the reachable attack surface by exposing routines, metadata and execution paths that ordinary read or write access does not need.

Q: Why can minimal SQL access still lead to database compromise?

A: Minimal SQL access can still reach dangerous code paths because query planning, function resolution and object access may invoke privileged engine behaviour beyond simple SELECT rights. If a role can trigger planner shortcuts, stored procedures or extension features, an attacker may move from low-privilege queries to data exposure, privilege escalation or code execution.

Q: How do temporary tables help exploit database bugs?

A: Temporary tables can help exploit database bugs because they create a private workspace for attacker-controlled objects, data types and query shapes inside the same session. That lets an exploit steer execution through unusual parser, optimiser or storage paths while reducing interference from shared database objects and normal access controls.

Q: What is the best way to reduce memory-corruption risk in databases?

A: The best way to reduce memory-corruption risk in databases is to harden the engine, minimise extension use and restrict risky session features such as unsafe procedural code, custom functions and privileged object creation. Memory corruption usually comes from flawed native code paths, so reducing exposure to those paths matters more than adding ordinary SQL permissions.


Technical breakdown

Why SQL grants do not bound native execution paths

SQL authorization limits what objects a session may touch, but it does not fully constrain which internal engine routines are invoked while processing a permitted statement. Query optimizers, aggregate evaluators, protocol parsers and type conversion code can all run inside the trusted database process. If any of those subsystems contain memory corruption or logic flaws, a narrow SQL role may still become a route to code execution because the privilege boundary stops at the logical layer, not at the native code that implements it. See the Authorisation Models Guide.

Practical implication: Treat database privilege design as necessary but insufficient when the engine exposes memory-unsafe native paths from ordinary SQL.

How temporary schemas expand the exploit surface

Temporary objects are often available by default or through broad application grants, and they give a session a private workspace to create tables, indexes, helper functions and aggregates. That matters because exploitability depends on shaping memory layout, feeding attacker-controlled values into engine internals and repeating the primitive until it becomes reliable. In PostgreSQL and MySQL, session-local features can provide the exact scaffolding needed to turn a subtle bug into a repeatable exploitation chain without touching production schemas.

Practical implication: Audit temporary-object privileges as part of database hardening, not as an optional convenience setting.

How type confusion turns planner shortcuts into memory corruption

Planner shortcuts can change the execution path enough to break type assumptions. When an engine skips a final conversion step or reuses an optimized code path that returns a different physical representation than the caller expects, a value can be misread as a pointer, a pointer can be misread as data, or a length check can be bypassed. Those mismatches are especially dangerous in C and C++ database engines because the wrong interpretation of a datum can immediately become arbitrary read or write capability.

Practical implication: Review optimization paths, not just syntax-level authorization, for places where return types and memory representations can diverge.


Threat narrative

Attacker objective: The attacker wants to turn a low-privilege database foothold into code execution under the database service account.

  1. Entry occurs through a minimally privileged SQL session or, in one chain, an exposed database endpoint before authentication completes.
  2. Credential or privilege abuse follows when the session can use temporary schemas, prepared statements or planner shortcuts to reach native engine code.
  3. Escalation comes from memory corruption, type confusion or out-of-bounds writes that convert logical SQL access into arbitrary code execution.
  4. Impact is host-level execution as the database service account, with access to files, secrets, cloud connectivity and adjacent systems.

Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Least privilege at the SQL layer is not a native execution boundary. Database teams often treat GRANT statements as the end of the access-control story, but the engine still exposes parser, optimizer and deserializer code to any session that can submit valid queries. That means the real question is not only what a role can read or write, but what native code that role can still drive. Practitioner takeaway: map the reachable engine surface behind every supposedly low-risk role.

Temporary object privileges are exploit primitives, not harmless conveniences. The ability to create temp tables, temp schemas or session-scoped helpers can supply heap grooming, index shaping and attacker-controlled object lifetimes. In this post's cases, those features make a memory bug repeatable and practical instead of theoretical. Practitioner takeaway: treat database credential and access security decisions as part of exploit containment, not just deployment convenience.

Type confusion inside database engines creates a direct path from query to control-flow hijack. When an optimizer or parser returns one physical representation while later code expects another, the database process may reinterpret data as pointers or pointers as data. That is especially dangerous in C and C++ engines because the mistake often becomes an immediate read or write primitive. Practitioner takeaway: prioritize memory-safe hardening and code-path review in any database component reachable from untrusted SQL.

Native database attack surface is wider than most grant reviews assume. A short grant list can hide broad exposure if the session can still invoke high-value internal routines through permitted features. The better governance model is to ask which engine subsystems remain reachable after authentication, not just which tables remain visible. Practitioner takeaway: include optimizer shortcuts, prepared statements and wire-format handlers in the threat model for every database tier.

What this signals

Native database execution paths deserve the same governance attention as visible tables and roles. The practical boundary for an attacker is not the grant list alone, but the set of internal routines a session can still exercise. Once a query can drive optimized execution, parser logic or binary deserialisation, role-based access control no longer tells the whole story.

Native attack surface: the exposed engine code that remains reachable after SQL permissions are applied. That surface is what turns temporary-object convenience, prepared statements and protocol handling into security-relevant control points. Database owners should model that surface explicitly, then remove unnecessary reach before an exploit chain can assemble.

Database hardening is no longer just about blocking reads and writes to sensitive schemas. It now also means deciding which engine subsystems a low-privilege session is allowed to invoke, because the path from query to host compromise can run through code that permissions were never designed to contain.


For practitioners

  • Revoke unnecessary temporary-object privileges Remove default or broad CREATE TEMPORARY TABLE and TEMPORARY rights where applications do not require them, especially on shared or multi-tenant databases.
  • Review query paths that skip final conversions Inspect optimizer fast paths, aggregate shortcuts and other execution rewrites that can return a different runtime type than the caller expects.
  • Harden exposed database endpoints before authentication Treat pre-login HTTP or wire-protocol interfaces as part of the attack surface and place them behind network controls, rate limits and exposure checks.
  • Reduce reliance on native engine code in privileged sessions Limit the use of session features that create attacker-controlled memory layouts, especially when those features are available to low-privilege accounts.

Key takeaways

  • Restrictive SQL grants do not automatically constrain the native code a database session can exercise, so the real attack surface is wider than the privilege list suggests.
  • Temporary-object privileges and planner shortcuts can turn low-privilege database access into memory corruption, arbitrary read primitives or full command execution.
  • Database defence should pair least privilege with exposure review for internal engine paths, especially where optimization rewrites, prepared statements or protocol parsers remain reachable.

Related NHI Mgmt Group resources: Database Credential and Access Security Guide · Authorisation Models Guide · Nmap for Defenders Guide · Vulnerability Severity and Bug Bar Guide for Development Teams


Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

MITRE ATT&CK and OWASP API Security Top 10 address the attack and risk surface, while NIST CSF 2.0, CIS Controls v8 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
MITRE ATT&CKTA0006; TA0004; TA0008 — Credential Access; Privilege Escalation; Lateral MovementThe exploit chains rely on low-privilege access, escalation through memory corruption and movement to host-level control.
Recommendation — Map database exploit chains to credential access, privilege escalation and lateral movement to prioritise detection coverage.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsSQL grants are the first boundary in the article, but they do not contain reachable engine code.
Recommendation — Review entitlements for database sessions and remove permissions that are not required for the application role.
CIS Controls v8CIS-5 — Account ManagementThe article hinges on how database accounts and temporary privileges shape exploitability.
Recommendation — Audit database account rights and strip unnecessary temporary or elevated privileges from application sessions.
NIST SP 800-53 Rev 5AC-6 — Least PrivilegeLeast privilege is necessary but insufficient when native engine paths remain exposed to ordinary queries.
Recommendation — Enforce least privilege for database accounts and pair it with control of reachable engine features.
OWASP API Security Top 10API8 — Security MisconfigurationExposed HTTP and wire-protocol endpoints expand the path from unauthenticated access to execution.
Recommendation — Harden exposed database interfaces and remove misconfigurations that allow unauthenticated request handling.

Key terms

  • Type Confusion: A software flaw where a program treats data as the wrong type. In protocol parsers, that mistake can cause crashes, memory corruption, or unsafe method calls when attacker-controlled input is decoded incorrectly and then passed into functions that expect a different data structure.
  • Temporary Schema: A temporary schema is a session-scoped database schema used to store transient tables, views or other objects. It exists only for the current connection or transaction context, so objects are isolated from normal persistent schemas unless the database exposes them through search paths or privileges.
  • Planner Fast Path: Planner fast path is a database optimiser shortcut that chooses a simpler execution plan without running the full planning process. It is used when the engine can satisfy a query from narrow patterns or cached knowledge, and it can change which code paths, indexes or permissions are exercised during execution.
  • Prepared Statement: A database query pattern that separates code from data so user input cannot change the structure of the statement. It is one of the most reliable ways to prevent injection because the database treats parameters as values, not executable query logic.

Deepen your knowledge

NHI Mgmt Group covers identity security, NHI governance, and agentic AI through independent research, practitioner guides, and the NHI Foundation Level course. Explore nhimg.org for resources that connect identity governance to the broader security disciplines your programme depends on.
NHIMG Editorial Note
Published by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org