About the End-User Security Context

In a typical scenario, the application connects to the database using a shared, highly privileged database user account (the connection pool user account). All queries run under this account’s identity, regardless of which end user is actually making the request.

This broad-access model creates a significant security risk; for example, a SQL injection attack or a compromised AI-generated query can run with the same elevated privileges as the application itself.

The end-user security context solves this problem. When active, it replaces the database session’s broad security domain (the connection pool user account and its roles) with the end user’s or application’s identity, data roles, and context attributes. Consequently, the database authorizes all executed SQL based on which end user or application is making the request, rather than the connection pool user account. This replacement is conceptually similar to the security context switch that occurs when a definer’s-rights PL/SQL procedure executes. Under this security model, the application’s database user account requires only basic privileges, such as CREATE SESSION and CREATE END USER SECURITY CONTEXT, effectively mitigating the risk of attacks like SQL injection.

How the security context is established

When the application initiates a database operation, the Oracle client driver (JDBC, Python, or ODP.NET) invokes a callback, enabling the application code to populate an EndUserSecurityContext object. Through this object, the application provides the following details to the database:

Single-token payloads use the following token variants:

For the single-token JDBC example, see Use the API Extension Methods.

Once populated, the client driver attaches the EndUserSecurityContext object to the database connection as metadata before sending the request to the database. The driver then forwards this metadata with every subsequent SQL request, ensuring that long-running connection-pool connections always operate under the correct, current security context. When the database receives the payload, it validates the supplied access token or tokens and establishes the end-user security context. The database creates, attaches, and destroys security contexts automatically; no custom session-management code is required in the application.

Note: The application can establish the database connection on which it attaches end-user security context payloads in either of two ways: by using a connection pool user account authenticated by a password, or by logging on directly as an application identity using a database-access token, including for an application identity–based connection pool. For application-only access, a client-credentials database-access token can establish the connection and also be supplied in the payload. For an OBO request, the connection can use a client-credentials database-access token, while the payload contains an OBO database-access token.

The attachment of the end-user security context payload and its enforcement are identical whether the database connection is established using a password-authenticated connection pool user account or an application identity. The application identified by the payload’s database-access token can differ from the application that established the connection. See Set Up IAM Integration for Application-Mediated Connections.

The direct logon option

Oracle AI Database also supports a direct logon option, in which the connecting principal establishes the session directly and the database natively establishes the end-user security context from the login. The connecting principal can be an end user or an application:

Note: