5.4 Policy Expressions That Use SYS_CONTEXT Attributes
Be careful when writing a policy expression that depends on a SYS_CONTEXT
attribute that is populated by an application.
If the user somehow connects directly (rather than through the application), then the SYS_CONTEXT
attribute would not have been populated. If you do not handle this NULL
scenario in your policy expression, you could unintentionally reveal actual data to the querying user.
For example, suppose you wanted to create a policy expression that intends to redact the query results for everyone except users who have the client identifier value of SUPERVISOR
. The following expression unintentionally enables querying users who have NULL
as the value for their CLIENT_IDENTIFIER
to see the real data:
SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') IS NOT 'SUPERVISOR'
A more rigorous policy expression redacts the result of the query if the client identifier is not set, that is, it has a NULL
value.
SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') IS NOT 'SUPERVISOR' OR IS NULL
Remember that in SQL, comparisons with NULL
are undefined, and are thus FALSE
, but redaction only takes place when the policy expression evaluates to TRUE
.