OracleSqlParser.Guard
0.11.0-preview.1
See the version list below for details.
dotnet add package OracleSqlParser.Guard --version 0.11.0-preview.1
NuGet\Install-Package OracleSqlParser.Guard -Version 0.11.0-preview.1
<PackageReference Include="OracleSqlParser.Guard" Version="0.11.0-preview.1" />
<PackageVersion Include="OracleSqlParser.Guard" Version="0.11.0-preview.1" />
<PackageReference Include="OracleSqlParser.Guard" />
paket add OracleSqlParser.Guard --version 0.11.0-preview.1
#r "nuget: OracleSqlParser.Guard, 0.11.0-preview.1"
#:package OracleSqlParser.Guard@0.11.0-preview.1
#addin nuget:?package=OracleSqlParser.Guard&version=0.11.0-preview.1&prerelease
#tool nuget:?package=OracleSqlParser.Guard&version=0.11.0-preview.1&prerelease
OracleSqlParser.Guard (EXPERIMENTAL)
Policy validation and access-restriction rewriting for user-supplied Oracle SELECT queries, built on
OracleSqlParser (namespace OracleSqlParser.Guard).
Targets net8.0 and net10.0. It depends on the OracleSqlParser package (minimum version as listed on nuget.org), which
NuGet installs automatically, so installing this package alone is enough. Guard is versioned separately and stays 0.x
while it is experimental, even after the core library reaches 1.0.
All public types are marked [Experimental("PLSQLGUARD001")]: using them is a compile error until you opt in with
<NoWarn>PLSQLGUARD001</NoWarn> (or #pragma warning disable PLSQLGUARD001). The API may change or be removed.
Limitations / not a security boundary
Do not rely on this package to protect data from an untrusted SQL author. The security review found the following known weaknesses. Treat the guard as a lint / convenience layer on top of a real database-side boundary.
RestrictToIdsfilters only the output key column. The wrapper isSELECT Q.* FROM (<user query>) Q WHERE Q.ID IN (<access query>), so rows are restricted only by the value that ends up in the output key column. Self-joins, scalar subqueries, correlatedEXISTS, aliasing (secret AS id), andMATCH_RECOGNIZE/UNPIVOT/MODELover the protected table can leak data from other rows. AFETCHinside the user query pages the rows before the filter is applied.- CTE names are resolved globally. A CTE named like an unlisted table exempts the real table when it is referenced outside the CTE's scope.
- Quoted identifiers are matched case-insensitively, although Oracle treats
"orders"andORDERSas different objects. AllowedFunctions == nullis fail-open. Unqualified user-defined functions, public synonyms (for examplegetxml),SYS_CONTEXT,BFILENAMEand similar pass the default rule. Only an explicit allow-list is restrictive.- Not denied:
XMLTABLE/XMLQUERYXQuery (ora:view,fn:collection),CURSOR(),CAST(MULTISET(...)),TABLE(),LATERAL, flashbackAS OF/VERSIONS,SAMPLE, andPARTITIONclauses. - Optimizer hints are copied verbatim into the generated SQL.
- No cost controls: cartesian joins,
CONNECT BYwithoutPRIOR, recursive CTEs and hugeFETCHcounts are all accepted. - Parser bug:
pkg.f(x).m()currently drops the receiver in the AST, so the function check can miss it. This is being fixed in the core library.
Recommended boundary
Use Oracle's own mechanisms as the real security boundary: Virtual Private Database (row-level security policies), secure views over the permitted data, and a minimally privileged database user with resource limits (profiles / Resource Manager). Use this package, if at all, as an additional layer.
Intended fixes
- Per-table filter substitution (replace each protected table reference with a filtered subquery) instead of filtering the output.
- Scope-aware CTE resolution.
- Default-deny function policy.
- Hint stripping.
- Re-validation of the generated output.
- Row cap and other cost controls.
Usage
using OracleSqlParser.Guard;
var policy = new QueryPolicy
{
AllowedTables = new HashSet<string>(["ORDERS", "CUSTOMERS"], StringComparer.OrdinalIgnoreCase),
AllowedFunctions = new HashSet<string>(["UPPER", "LOWER", "TRUNC", "NVL"], StringComparer.OrdinalIgnoreCase), // use an allow-list
RequiredColumns = ["ID"],
};
var filter = new AccessFilter
{
KeyColumn = "ID",
AccessSql = "SELECT order_id FROM user_orders WHERE user_id = :accessUserId",
};
GuardedSql g = QueryGuard.RestrictToIds(userSql, policy, filter); // throws QueryRejectedException with all violations
var rows = connection.Query(g.Sql, new { accessUserId = 42, /* the user's own binds */ });
g.Sql is SELECT Q.* FROM (<user query>) Q WHERE Q.ID IN (<access query>): the restriction is applied outside the user's
query, so OR, UNION and GROUP BY inside it do not remove the filter (but see the limitations above).
QueryGuard.Validate checks a query against the policy without wrapping it. The generated SQL is verified by re-parsing and,
in the repository's integration tests, by running it against Oracle 23 Free. The user's top-level ORDER BY is moved outside
the wrapper only when expressible on output columns. Output is Oracle SQL only.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- OracleSqlParser (>= 1.0.0-rc.4)
-
net8.0
- OracleSqlParser (>= 1.0.0-rc.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.11.1-preview.1 | 53 | 11/21/2026 |
| 0.11.0-preview.1 | 88 | 11/20/2026 |
| 0.10.0-preview.1 | 54 | 11/19/2026 |
| 0.9.0-preview.1 | 52 | 11/18/2026 |
| 0.8.0-preview.1 | 58 | 11/16/2026 |
| 0.7.0-preview.1 | 56 | 11/14/2026 |
| 0.6.0-preview.1 | 52 | 11/14/2026 |
| 0.5.0-preview.1 | 60 | 11/14/2026 |