Security & Ops Series: 26ai in practice

Oracle 26ai SQL Firewall: The Allow List Learns Your App. Then a New Server Can't Log In.

· 9 min read

SQL injection, a stolen application password, a developer who connects as the app account “just to check something”: they all end the same way, with SQL the application never runs, executed under the application’s user. Oracle AI Database 26ai has a database-level answer built in: SQL Firewall. You let it watch an application user for a while, it turns what it saw into an allow list, and from then on it can block every statement, and every connection, that isn’t on the list.

The procedure fits on a slide: capture, generate, enable. I ran it on Oracle AI Database 26ai Free against a small application and then did the things that happen after go-live: the month-end report, a release, a second app server, a fix at 2 a.m. Each one ran into a rule that the slide leaves out.

The setup

User APP owns an ORDERS table and a procedure, MARK_PAID. A separate user with the SQL_FIREWALL_ADMIN role runs the firewall:

EXEC DBMS_SQL_FIREWALL.ENABLE;                       -- once; no restart needed
EXEC DBMS_SQL_FIREWALL.CREATE_CAPTURE('APP');        -- starts capturing APP's SQL and session context

-- ... the application runs its normal "daytime" workload ...

EXEC DBMS_SQL_FIREWALL.STOP_CAPTURE('APP');
EXEC DBMS_SQL_FIREWALL.GENERATE_ALLOW_LIST('APP');
EXEC DBMS_SQL_FIREWALL.ENABLE_ALLOW_LIST('APP');

The daytime workload was a few lookups by id, a status update and a call to MARK_PAID. The month-end report, a GROUP BY over ORDERS, didn’t run during the capture, which is what happens when you capture for a week in the middle of the month.

SQL Firewall is part of Oracle Database Free. On Enterprise Edition the licensing manual lists it as included with the Database Vault option (or with Oracle Audit Vault and Database Firewall), so check that before you plan on it.

Enabled doesn’t mean blocking

After ENABLE_ALLOW_LIST('APP'), DBA_SQL_FIREWALL_ALLOW_LISTS says ENABLED, ENFORCE_ALL. The month-end report still ran. The only trace was a row in DBA_SQL_FIREWALL_VIOLATIONS: SQL violation, firewall action Allowed.

The block parameter of ENABLE_ALLOW_LIST defaults to FALSE. The package reference says so, and the lab’s BLOCK column said N. That’s a sensible way to start, since you can watch the violation log before anything breaks, but “we enabled the SQL Firewall” and “the SQL Firewall blocks” are two different statements:

EXEC DBMS_SQL_FIREWALL.UPDATE_ALLOW_LIST_ENFORCEMENT('APP', block => TRUE);

What counts as the same SQL

With blocking on, the captured lookup select customer, amount from orders where id = 1 ran with any other id, and in any case and spacing (SELECT Customer, AMOUNT from ORDERS where ID=8). SQL Firewall stores a normalized form, with the literals replaced: SELECT CUSTOMER,AMOUNT FROM ORDERS WHERE ID=:"SYS_B_0".

These failed, each with the same error:

select customer, sum(amount) from orders group by customer ...   -- the month-end report
select amount, customer from orders where id = 7                 -- the same columns, swapped
select customer, amount from orders where id = :b                -- a bind variable instead of the literal

ORA-47605: SQL Firewall violation

The swapped columns are the point of the feature. The bind variable is the surprise: the captured statement had a literal, so the statement with a bind is different SQL. An application fix that moves from literals to binds, the standard cure for a hard-parse storm, turns into blocked statements.

SQL inside PL/SQL is checked too. A release changed the UPDATE inside MARK_PAID by adding one column to its SET clause. The call to MARK_PAID was still on the allow list; the statement inside it wasn’t:

SQL> exec mark_paid(6)
ORA-47605: SQL Firewall violation
ORA-06512: at "APP.MARK_PAID", line 3

Every release that changes a statement, in the application or in a procedure it calls, changes the allow list.

The second app server can’t log in

The capture also records where the SQL came from. For the daytime workload, the allow list held three values:

IP address   127.0.0.1
OS user      oracle
OS program   sqlplus@dbhost (TNS V1-V3)

With ENFORCE_ALL (the default), a session must match those as well as the SQL. Then the same application, same user, same password, started on a second server, appsrv2:

ERROR:
ORA-47605: SQL Firewall violation
SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

It couldn’t log in. The violation log said Context violation, IP 172.28.0.3, program sqlplus@appsrv2 (TNS V1-V3). The obvious fix, allowing the new IP with ADD_ALLOWED_CONTEXT, wasn’t enough: the login still failed, because the program name contains the client’s host name. Only after adding sqlplus@appsrv2 (TNS V1-V3) as an allowed OS program did appsrv2 get in. Then appsrv3 was refused, for the same reason.

A pattern doesn’t help. With sqlplus@% added and every IP allowed (%), appsrv3 was still refused: % isn’t matched as a wildcard inside a string. On its own it allows any value, and a bare % as the program let the next server in, which also means the program is no longer checked at all. So for clients whose program name contains the host, which SQL*Plus does, every new host, every rebuilt container and every autoscaled node is a new value. Check V$SESSION.PROGRAM for your own driver before you rely on context. The other option is to enforce only the SQL:

EXEC DBMS_SQL_FIREWALL.UPDATE_ALLOW_LIST_ENFORCEMENT('APP', enforce => DBMS_SQL_FIREWALL.ENFORCE_SQL);

With ENFORCE_SQL, appsrv3 logged in, ran the lookup, and was still blocked on the month-end report.

From capture to enforcement. Every session of APP is checked against the context at login and against the SQL on each statement; anything outside the list is logged, and blocked only when BLOCK = TRUE.

The 2 a.m. fix approves more than you meant

The month-end report is blocked, the business is waiting, and the package has a procedure that sounds exactly right: APPEND_ALLOW_LIST(username, source) with source => DBMS_SQL_FIREWALL.VIOLATION_LOG adds the statements from the violation log to the allow list.

It works, and fast. In the lab, an application session that was already connected got ORA-47605 for the report, the log was appended, and the same session ran the report 15 seconds later without reconnecting. The allow list went from 6 statements to 8.

The 8th was the swapped-column probe from another session, which had landed in the same violation log. It was allowed now too. Appending the violation log approves everything in it: the report, and whatever else was rejected in the meantime, including the statements the firewall was there to stop.

The narrow version takes one statement by its signature:

SELECT sql_signature, sql_text
FROM   dba_sql_firewall_violations
WHERE  username = 'APP';

EXEC DBMS_SQL_FIREWALL.APPEND_ALLOW_LIST_SINGLE_SQL( -
  username => 'APP', sql_signature => '<signature of the report>', -
  current_user => 'APP', top_level => 'Y');

With that, the report ran and the probe was still blocked. Recent violations are held in memory and written to the log tables in the background; run DBMS_SQL_FIREWALL.FLUSH_LOGS before you query the log or append from it.

Log-only mode has a storage bill

The violation log records every execution, not every distinct statement. With BLOCK = FALSE, one statement that wasn’t on the list, run 100,000 times in a loop, wrote 100,003 rows to DBA_SQL_FIREWALL_VIOLATIONS, and the table behind it, SYS.VIOLATION_LOG$ in SYSAUX, grew from 0.1 MB to 13 MB. A busy application left in log-only mode with a hot statement that the capture missed writes that much for every 100,000 executions, until someone purges it:

EXEC DBMS_SQL_FIREWALL.PURGE_LOG(username => 'APP', log_type => DBMS_SQL_FIREWALL.VIOLATION_LOG);

The getting started guide recommends monitoring and purging the violation logs periodically. Put it in the same job that watches them.

Who isn’t covered

  • SYS. CREATE_CAPTURE('SYS') fails with ORA-47621: The SQL Firewall operation is not allowed on user SYS. It’s built for application accounts; SYS is outside it.
  • Users without an allow list. Enforcement is per user. A DBA account, or a second application account nobody captured, isn’t checked at all.
  • Scheduler jobs, by default. They’re excluded (DBA_SQL_FIREWALL_STATUS.EXCLUDE_JOBS = Y). A job that APP created ran, as APP, an UPDATE that wasn’t on the list, with blocking on, and nothing was logged. Anything APP can schedule runs outside the firewall.

INCLUDE(DBMS_SQL_FIREWALL.SCHEDULER_JOB) changes that, and the package reference says it enables capture and enforcement for scheduler jobs. It also changes what a job needs: the same job then failed with ORA-47605 as a context violation, because the job slave’s session context wasn’t on the allow list captured from the application. Include jobs before the capture, and let the jobs run during it, or they stop the night you switch it on.

The cost of checking is small. 200,000 executions of an allowed statement in a PL/SQL loop took 0.70 to 0.74 seconds with the allow list enforced and 0.68 to 0.69 seconds with it disabled, across three lab runs.

Prove it

The lab runs Oracle AI Database 26ai Free (23.26.3), plus short-lived client containers from the same image as “other app servers”:

drill     case                                                 result
capture   ENABLE_ALLOW_LIST with the defaults                  ENFORCE_ALL, BLOCK = N: the report runs, logged
          allowed OS program                                   'sqlplus@dbhost (TNS V1-V3)'
          CREATE_CAPTURE('SYS')                                ORA-47621
block     captured lookup, other literal / case / spacing     runs
          month-end report; swapped columns; bind variable     ORA-47605
release   UPDATE inside MARK_PAID changed                      ORA-47605 at "APP.MARK_PAID"
newhost   appsrv2                                              can't log in: ORA-47605, Context violation
          + its IP / + 'sqlplus@appsrv2 (TNS V1-V3)'           still refused / logs in
          appsrv3, with '%' IP and 'sqlplus@%'                 refused
          ENFORCE_SQL                                          appsrv3 logs in; the report still blocked
          ENFORCE_ALL, program '%'                             appsrv4 logs in
recover   APPEND_ALLOW_LIST(VIOLATION_LOG)                     report runs in the open session; probe allowed too
          APPEND_ALLOW_LIST_SINGLE_SQL                         report runs; probe still blocked
logonly   BLOCK = FALSE, 100,000 x one unlisted statement      100,003 violation rows; VIOLATION_LOG$ 0.1 -> 13 MB
          PURGE_LOG                                            0 rows
jobs      job created by APP, unlisted UPDATE (default)        runs as APP, nothing logged
          the same job, INCLUDE(SCHEDULER_JOB)                 ORA-47605, Context violation
overhead  200,000 x allowed statement, enforced vs disabled    ~0.71 s vs ~0.69 s

Don’t take my word for it — run it. The sql-firewall lab asserts every row: the default BLOCK = N, what passes and what fails with ORA-47605, the error inside the changed procedure, the login refused from a new host and what lets it in, what APPEND_ALLOW_LIST approves, the violation rows and the SYSAUX growth, and the job that runs unchecked by default and fails when included. If any of it doesn’t reproduce, the run fails. Proven on every CI push.

What the lab doesn’t cover: JDBC, ODP.NET and python-oracledb clients (it uses SQLPlus, so the program names are SQLPlus’s), RAC, Data Guard, Database Vault, and Oracle Data Safe, which can manage SQL Firewall for you.

What teams get wrong

  • Taking “enabled” for “blocking”. ENABLE_ALLOW_LIST logs by default. Check the BLOCK column, and set it on purpose.
  • Capturing a quiet week. Whatever didn’t run during the capture, the month-end report, the quarterly cleanup, the rarely used admin screen, is a violation later. Capture across a full business cycle, or run log-only through one before you block.
  • Shipping SQL changes without the allow list. A new statement, a changed procedure body, or a switch from literals to binds is new SQL. Update the allow list in the same release.
  • Enforcing context with a host name in it. The allowed program was sqlplus@dbhost. A new server, container or node couldn’t log in, and allowing its IP didn’t fix it.
  • Appending the whole violation log. It approves every statement in the log, including the ones the firewall exists to stop. Review the log and append single statements.
  • Forgetting the scheduler. By default, jobs run outside the firewall; included, they need their own context on the list.
  • Leaving log-only mode running. One row per execution, in SYSAUX. Purge it, and fix what fills it.

Frequently asked questions

What is Oracle SQL Firewall?

A database feature (DBMS_SQL_FIREWALL) that captures the SQL statements and the session context (client IP address, OS user, OS program) of a database user, turns them into an allow list, and then logs or blocks any statement or connection that isn't on it. It's part of Oracle Database Free; on Enterprise Edition it's included with the Database Vault option or with Oracle Audit Vault and Database Firewall.

Why doesn't SQL Firewall block anything after ENABLE_ALLOW_LIST?

Because the block parameter of DBMS_SQL_FIREWALL.ENABLE_ALLOW_LIST defaults to FALSE: violations are logged in DBA_SQL_FIREWALL_VIOLATIONS with the action 'Allowed', and the statement runs. Turn blocking on with DBMS_SQL_FIREWALL.UPDATE_ALLOW_LIST_ENFORCEMENT(username, block => TRUE), and check the BLOCK column of DBA_SQL_FIREWALL_ALLOW_LISTS.

What does ORA-47605: SQL Firewall violation mean?

The session or the statement wasn't on the user's SQL Firewall allow list and blocking is on. For a statement, the statement fails; for a context violation (an IP address, OS user or OS program that isn't allowed), the login itself fails. DBA_SQL_FIREWALL_VIOLATIONS shows which one, with the cause 'SQL violation' or 'Context violation'. Run DBMS_SQL_FIREWALL.FLUSH_LOGS first if the latest ones are missing.

Does SQL Firewall treat statements with different literals as the same SQL?

Yes. It stores a normalized form with the literals replaced, and in the companion lab the captured lookup ran with any other literal and with other case and spacing. A different column order, or a bind variable where the captured statement had a literal, is different SQL and failed with ORA-47605.

Why can't my application log in from a new server after enabling SQL Firewall?

With ENFORCE_ALL, the default, the session context has to match the allow list too: client IP address, OS user and OS program. For SQL*Plus the program name includes the client's host name (sqlplus@host), so a new server is a new program. In the companion lab, allowing the new IP wasn't enough and 'sqlplus@%' didn't match; adding the exact program name, or switching to ENFORCE_SQL, let it in.

Is APPEND_ALLOW_LIST from the violation log safe?

It adds every statement in the violation log to the allow list. In the companion lab it fixed the blocked report in an already connected session, and also allowed a probe statement that had been blocked in the same period. To add one statement, use DBMS_SQL_FIREWALL.APPEND_ALLOW_LIST_SINGLE_SQL with its SQL signature from DBA_SQL_FIREWALL_VIOLATIONS.

Does SQL Firewall protect SYS and scheduler jobs?

Not SYS: CREATE_CAPTURE('SYS') fails with ORA-47621. Scheduler jobs are excluded by default (EXCLUDE_JOBS = Y in DBA_SQL_FIREWALL_STATUS): in the companion lab a job created by the protected user ran an unlisted UPDATE with nothing logged. DBMS_SQL_FIREWALL.INCLUDE(SCHEDULER_JOB) brings them in; the same job then failed with ORA-47605 as a context violation, because the job slave's context wasn't on the allow list.

SQL Firewall does what it promises: outside the list, nothing runs, and that includes a stolen password used from the wrong host. What the slide leaves out is that the list has to be right first. Turn on blocking on purpose, capture a full cycle, ship allow-list changes with every release, decide whether host names belong in it, and append one statement at a time. Prove each one with the sql-firewall lab.

Have a question or some feedback?

I write here in a personal capacity and enjoy comparing notes with other Oracle folks. Say hello.

Get in touch