top of page

Oracle SQL Firewall in Oracle Database 23ai — From Capture to Enforcement Runbook

OmerNarman
Sep 29
5 min read

Updated: Oct 24

Environment used in this runbook:

  • Database: Oracle Database 23ai, PDB PDB1

  • Application account: APP_USER

  • Security administrator: SEC_ADMIN

  • Licensing: SQL Firewall is built into the 23ai kernel and included with Enterprise Edition, no separate option


What SQL Firewall is

SQL Firewall sits inside the database kernel and evaluates every SQL statement of a protected user against an allow-list: the set of normalised SQL statements the application is known to run, plus the session context it is allowed to use (client IP addresses, OS users, client programs). Anything else is logged, or logged and blocked. Because it inspects SQL after parsing, it cannot be fooled by encoding tricks, and literal values do not matter (WHERE id = 1 and WHERE id = 2 are the same statement).

Use cases: stop SQL injection through the application account, stop credential abuse from unexpected hosts/tools, prove "only known SQL runs against this schema".

Lifecycle: enable → capture → generate allow-list → enable allow-list in log-only mode → review violations → block.

Step 1 — Grant the administrator roles

SQL

ALTER SESSION SET CONTAINER = PDB1;

CREATE USER sec_admin IDENTIFIED BY "SecAdmin#2026";

GRANT CREATE SESSION TO sec_admin;

GRANT SQL_FIREWALL_ADMIN TO sec_admin; -- manage captures, allow-lists, enforcement

GRANT SQL_FIREWALL_VIEWER TO sec_audit; -- read-only access to logs and views

Why: SQL_FIREWALL_ADMIN bundles EXECUTE ON DBMS_SQL_FIREWALL and SELECT on all DBA_SQL_FIREWALL_* views. Do not run the firewall from SYS.

Step 2 — Enable SQL Firewall in the PDB

SQL

-- as SEC_ADMIN

EXEC DBMS_SQL_FIREWALL.ENABLE;

SELECT * FROM dba_sql_firewall_status; -- STATUS = ENABLED

Why: enabling is per-PDB and does nothing to users yet; it only switches on the mechanism.

Step 3 — Capture the application's SQL

SQL

BEGIN

DBMS_SQL_FIREWALL.CREATE_CAPTURE(

username => 'APP_USER',

top_level_only => FALSE, -- also record SQL executed inside PL/SQL

start_capture => TRUE);

END;

/

Now run the complete application workload: every screen, batch job, month-end process, admin function. Capture for as long as it takes to cover them all (days or weeks in real projects).

SQL

-- what has been captured so far

SELECT sql_text, current_user, client_program, ip_address, os_user

FROM dba_sql_firewall_capture_logs

WHERE username = 'APP_USER' ORDER BY sql_text;

SELECT * FROM dba_sql_firewall_session_logs WHERE username = 'APP_USER';

EXEC DBMS_SQL_FIREWALL.FLUSH_LOGS; -- force in-memory log buffers to disk before reading

EXEC DBMS_SQL_FIREWALL.STOP_CAPTURE('APP_USER');

Why: the allow-list is only as good as the capture. Missed workload = false violations later. top_level_only => TRUE is cheaper but leaves statements inside stored procedures uncontrolled; keep FALSE for application accounts that call PL/SQL.

Step 4 — Generate the allow-list

SQL

EXEC DBMS_SQL_FIREWALL.GENERATE_ALLOW_LIST('APP_USER');

-- review what will be allowed

SELECT sql_text, sql_signature FROM dba_sql_firewall_allowed_sql WHERE username = 'APP_USER' ORDER BY 1;

SELECT ip_address FROM dba_sql_firewall_allowed_ip_addr WHERE username = 'APP_USER';

SELECT os_program FROM dba_sql_firewall_allowed_os_prog WHERE username = 'APP_USER';

SELECT os_user FROM dba_sql_firewall_allowed_os_user WHERE username = 'APP_USER';

SELECT * FROM dba_sql_firewall_allow_lists;

Why: the allow-list is created from the capture logs and contains both the SQL and the session context. Review it with the application team; remove anything that should not be there (e.g. SELECT * FROM all_tables from a developer's SQL Developer session).

SQL

-- remove one statement or add a context value by hand

EXEC DBMS_SQL_FIREWALL.DELETE_ALLOWED_SQL(username => 'APP_USER', sql_id => 42); -- SQL_ID from DBA_SQL_FIREWALL_ALLOWED_SQL

EXEC DBMS_SQL_FIREWALL.ADD_ALLOWED_CONTEXT(username => 'APP_USER', context_type => DBMS_SQL_FIREWALL.IP_ADDRESS, value => '10.10.20.31');

EXEC DBMS_SQL_FIREWALL.ADD_ALLOWED_CONTEXT(username => 'APP_USER', context_type => DBMS_SQL_FIREWALL.OS_PROGRAM, value => 'JDBC Thin Client');

Step 5 — Enable the allow-list in log-only mode (observe, don't block)

SQL

BEGIN

DBMS_SQL_FIREWALL.ENABLE_ALLOW_LIST(

username => 'APP_USER',

enforce => DBMS_SQL_FIREWALL.ENFORCE_ALL, -- ENFORCE_SQL | ENFORCE_CONTEXT | ENFORCE_ALL

block => FALSE); -- log violations, let them run

END;

/

Why: block => FALSE is your safety net: run production for a week and look at every violation before anything is blocked. ENFORCE_CONTEXT alone is a quick win against credential theft (right SQL from the wrong host is still a violation).

Step 6 — Review violations

SQL

EXEC DBMS_SQL_FIREWALL.FLUSH_LOGS;

SELECT occurred_at, sql_text, firewall_action, cause, ip_address, os_user, client_program

FROM dba_sql_firewall_violations

WHERE username = 'APP_USER' ORDER BY occurred_at DESC;

Typical findings and the fix:

  • Legitimate SQL missed during capture → append it: EXEC DBMS_SQL_FIREWALL.APPEND_ALLOW_LIST(username => 'APP_USER', source => DBMS_SQL_FIREWALL.VIOLATION_LOG);

  • New release added statements → run a new capture and append from it: source => DBMS_SQL_FIREWALL.CAPTURE_LOG.

  • New application server → ADD_ALLOWED_CONTEXT with its IP.

  • Somebody using the application credentials from a laptop → this is the finding you built the firewall for.

Why: CAUSE distinguishes SQL violation from Context violation, so you know whether to fix the SQL list or the context list.

Step 7 — Switch to blocking

SQL

BEGIN

DBMS_SQL_FIREWALL.UPDATE_ALLOW_LIST_ENFORCEMENT(

username => 'APP_USER',

enforce => DBMS_SQL_FIREWALL.ENFORCE_ALL,

block => TRUE);

END;

/

A blocked statement receives:

SQL

ORA-47605: SQL Firewall violation

Why: the application gets an error instead of executing the statement; make sure the application handles it gracefully and that monitoring alerts on ORA-47605.

Step 8 — Integrate with auditing and monitoring

SQL

-- violations can be written to the unified audit trail with a SQL_FIREWALL component policy

-- (VIOLATION = violations only; ALL = every SQL Firewall event for that user)

CREATE AUDIT POLICY fw_violations ACTIONS COMPONENT = SQL_FIREWALL VIOLATION ON app_user;

AUDIT POLICY fw_violations;

SELECT event_timestamp, dbusername, fw_action_name, fw_return_code, sql_text

FROM unified_audit_trail

WHERE unified_audit_policies LIKE '%FW_VIOLATIONS%' ORDER BY 1 DESC;

Why: the audit trail is your tamper-evident record and it is what Data Safe / SIEM collectors read. Every call to DBMS_SQL_FIREWALL is audited mandatorily, so allow-list changes are traceable as well. Turn violation auditing on only after training is complete; both DBA_SQL_FIREWALL_VIOLATIONS and the audit trail can grow fast under attack — schedule purges.

Step 9 — Housekeeping

SQL

-- purge old logs

EXEC DBMS_SQL_FIREWALL.PURGE_LOG(username => 'APP_USER', purge_time => SYSTIMESTAMP - 30, log_type => DBMS_SQL_FIREWALL.VIOLATION_LOG);

EXEC DBMS_SQL_FIREWALL.PURGE_LOG(username => 'APP_USER', purge_time => SYSTIMESTAMP - 30, log_type => DBMS_SQL_FIREWALL.CAPTURE_LOG);

-- export / import an allow-list between environments (JSON)

DECLARE

l_json CLOB;

BEGIN

DBMS_SQL_FIREWALL.EXPORT_ALLOW_LIST(username => 'APP_USER', allow_list => l_json);

-- store l_json; on the target PDB:

-- DBMS_SQL_FIREWALL.IMPORT_ALLOW_LIST(username => 'APP_USER', allow_list => l_json);

END;

/

-- temporary suspension / removal

EXEC DBMS_SQL_FIREWALL.DISABLE_ALLOW_LIST('APP_USER');

EXEC DBMS_SQL_FIREWALL.DROP_ALLOW_LIST('APP_USER');

EXEC DBMS_SQL_FIREWALL.DROP_CAPTURE('APP_USER');

EXEC DBMS_SQL_FIREWALL.DISABLE; -- whole PDB

Why: build the allow-list in test, export it as JSON, import it in production, then run a short capture there only to catch environment-specific context (IPs, programs).

Operating rules

  1. Protect application service accounts first; they are the SQL-injection vector. Human DBA accounts are better handled with Database Vault and auditing.

  2. Every application release: capture in test → APPEND_ALLOW_LIST → export/import → short log-only period in production → block.

  3. Keep block => FALSE for at least one full business cycle (month-end!) before blocking.

  4. Alert on ORA-47605 and on rows in DBA_SQL_FIREWALL_VIOLATIONS with cause = 'Context violation' — those are the credential-abuse signals.

  5. Overhead is small (the evaluation is a hash lookup per statement), but logging thousands of violations per second is not — set block => TRUE before an attack, not during one.

Recent Posts

See All

Comments


bottom of page