For security teams

Cover the SQL layer in your code-scanning program.

For the application and product security engineers who run code scanning. Lexega analyzes stored procedures, migrations, grants and dynamic SQL as code in their own right, and reports into the tools you already use.

curl -sSL https://lexega.com/install.sh | sh

Free to run. No key, no account, no email. macOS and Linux; Windows download. Start a 30-day trial

Prefer to verify first? Each GitHub release carries the binaries, CHECKSUMS.sha256 and an SBOM for each binary. The install script checks the same checksum.

What it adds to your program

Cover the SQL itself

Stored procedures, migrations, grants and dynamic SQL, analyzed as code in seven SQL dialects, including T-SQL.

Follow injection to the line that runs it

Input traced through variables, branches and procedure calls to the statement that executes it. A parameterized version of the same code is not flagged.

Fits the program you run

SARIF for GitHub code scanning, GitLab's security report format, a CI gate, and under your policy a recorded decision for every run.

An injection that crosses a procedure boundary

Each statement looks reasonable on its own. Lexega follows the value from where it enters to where it runs.

  1. Step 1A search term arrives as a parameter of run_search.
  2. Step 2Another procedure wraps it in QUOTENAME(), which does not make it safe inside a string, and hands it back.
  3. Step 3The result is concatenated into a query string.
  4. Step 4: blockedsp_executesql runs the string. Lexega reports the injection at this line.
The same procedure with the term bound as a parameter is allowed. Tracing across procedures needs a trial or Team key.See what the engine reports

Injection and exposure, as the engine reports them

Each example is real SQL with Lexega's verdict. Open one for the full statement, what the engine reported and a near-identical safe version that comes back allowed.

Recorded from lexega-sql 3.0.0 with a trial or Team key, under a policy that blocks critical findings and warns on high ones. Enforcing a policy needs no key; each example says what a run without one reports. To check one, install Lexega and run lexega-sql analyze on the example's SQL.

Injection through another procedure

EXEC dbo.build_clause @term, @clause OUTPUT;
DECLARE @sql NVARCHAR(800) = N'SELECT * FROM users ' + @clause;
EXEC sp_executesql @sql;

Blocked. The version that binds the term as a parameter is allowed.

Without a key: PROC-DYNSQL at high, on the sp_executesql line. Tracing the value through the other procedure, DYNSQL-CONCAT at critical, needs a trial or Team key.

Full SQL, engine output and its safe twin

Injection across a procedure boundary: input flows through an OUTPUT parameter and QUOTENAME() before execution

-- Untrusted @term crosses into build_clause, is wrapped in QUOTENAME()
-- (not a sanitizer in a string-literal context), returned via an OUTPUT
-- parameter, then concatenated and executed back in the caller.
CREATE PROCEDURE dbo.build_clause @raw NVARCHAR(200), @out NVARCHAR(400) OUTPUT
AS
BEGIN
  SET @out = N'WHERE name = ''' + QUOTENAME(@raw) + N'''';
END;
GO

CREATE PROCEDURE dbo.run_search @term NVARCHAR(200)
AS
BEGIN
  DECLARE @clause NVARCHAR(400);
  EXEC dbo.build_clause @term, @clause OUTPUT;
  DECLARE @sql NVARCHAR(800) = N'SELECT * FROM users ' + @clause;
  EXEC sp_executesql @sql;
END;
GO
BLOCKEDBlocked by severity_actions.critical (finding severity = critical)
CRITICALDYNSQL-CONCAT

Dynamic SQL argument is built via string concatenation or FORMAT(...) interpolation. SQL injection risk — switch to a parameterized query (USING clause / sp_executesql parameter binding).

lexega-sql 3.0.0 · mssql · with a key

The same search, parameterized. The helper procedure is gone and the term is bound as an sp_executesql parameter instead of concatenated, so the search is allowed.

-- Identical intent, but @term is bound via sp_executesql parameters
-- instead of being concatenated into the statement text.
CREATE PROCEDURE dbo.run_search @term NVARCHAR(200)
AS
BEGIN
  DECLARE @sql NVARCHAR(800) = N'SELECT * FROM users WHERE name = @p';
  EXEC sp_executesql @sql, N'@p NVARCHAR(200)', @p = @term;
END;
GO
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · mssql · with a key

Injection three assignments away from where it runs

a := 'ALTER TABLE fct_events ADD COLUMN ' || target_col || ' VARCHAR';
b := a;
c := b;
EXECUTE IMMEDIATE c;

Blocked. The same relay with the value bound through USING is allowed.

Without a key: PROC-DYNSQL at high, on the line that runs the string. Tracing the concatenation to that line, DYNSQL-CONCAT at critical, needs a trial or Team key.

Full SQL, engine output and its safe twin

Injection, three hops from where it runs: the variable that is executed looks clean on its own line, but the concatenation that carries the input is three assignments back, behind a decoy

-- The sink runs a bare variable. The concatenation that taints it is
-- three assignments back; a decoy copy is returned, never executed.
CREATE OR REPLACE PROCEDURE etl.add_audit_column(target_col VARCHAR)
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
DECLARE
  a VARCHAR;
  b VARCHAR;
  c VARCHAR;
  preview VARCHAR;
BEGIN
  a := 'ALTER TABLE fct_events ADD COLUMN ' || target_col || ' VARCHAR';
  b := a;
  preview := 'ddl: ' || b;
  c := b;
  EXECUTE IMMEDIATE c;
  RETURN preview;
END;
$$;
BLOCKEDBlocked by severity_actions.critical (finding severity = critical)
CRITICALDYNSQL-CONCAT

Dynamic SQL argument is built via string concatenation or FORMAT(...) interpolation. SQL injection risk — switch to a parameterized query (USING clause / sp_executesql parameter binding).

lexega-sql 3.0.0 · snowflake · with a key

Same relay, same bare-variable sink. Chasing c ← b ← a finds a constant template this time, with the runtime value bound via USING — so it’s allowed. The verdict tracks the data flow, not the shape.

-- Same three-hop relay, same bare-variable sink. But the traced value
-- is a constant template; the runtime value is bound with USING.
CREATE OR REPLACE PROCEDURE etl.count_tenant_events(tenant_id VARCHAR)
RETURNS VARCHAR
LANGUAGE SQL
AS
$$
DECLARE
  a VARCHAR;
  b VARCHAR;
  c VARCHAR;
BEGIN
  a := 'SELECT COUNT(*) FROM fct_events WHERE tenant_id = ?';
  b := a;
  c := b;
  EXECUTE IMMEDIATE c USING (tenant_id);
  RETURN 'ok';
END;
$$;
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · snowflake · with a key

A masking policy that masks nothing

CREATE MASKING POLICY mask_ssn AS (val STRING) RETURNS STRING ->
  CASE WHEN CURRENT_ROLE() = 'ADMIN' THEN val ELSE val END;

Blocked. A policy that masks the other branch is allowed.

Without a key: the same finding, MASK-ALLOW-ALL at critical.

Full SQL, engine output and its safe twin

Data exposure: a masking policy that masks nothing

-- Looks conditional. Every branch returns the input untouched.
CREATE MASKING POLICY mask_ssn AS (val STRING) RETURNS STRING ->
  CASE WHEN CURRENT_ROLE() = 'ADMIN' THEN val ELSE val END;
BLOCKEDBlocked by severity_actions.critical (finding severity = critical)
CRITICALMASK-ALLOW-ALL

Masking Policy body passes through the original value without masking. Policy is effectively a no-op and sensitive data may be exposed.

lexega-sql 3.0.0 · snowflake · with a key

Same policy, real masking. The non-admin branch actually masks, so the same policy shape is allowed.

-- Same policy. The non-admin branch actually masks.
CREATE MASKING POLICY mask_ssn AS (val STRING) RETURNS STRING ->
  CASE WHEN CURRENT_ROLE() = 'ADMIN' THEN val ELSE '***-**-****' END;
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · snowflake · with a key

A cloud access key committed in a stage

CREATE OR REPLACE STAGE raw.vendor_drop
  URL = 's3://acme-vendor-drop/inbound/'
  CREDENTIALS = (AWS_KEY_ID = 'AKIA...' AWS_SECRET_KEY = '...');

Blocked. The same stage through a storage integration is allowed.

Without a key: the same finding, CRED-AWS-LEAK at critical.

Full SQL, engine output and its safe twin

Secrets: a stage that works, with its cloud access key committed in the DDL

-- The stage works. Its access key is now in version control.
CREATE OR REPLACE STAGE raw.vendor_drop
  URL = 's3://acme-vendor-drop/inbound/'
  CREDENTIALS = (AWS_KEY_ID = 'AKIAIOSFODNN7EXAMPLE'
                 AWS_SECRET_KEY = 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY');
BLOCKEDBlocked by severity_actions.critical (finding severity = critical)
CRITICALCRED-AWS-LEAK

Hardcoded AWS credentials detected (access key ID, secret access key, or session token). Never commit credentials to source code. Use secure parameter passing, secrets managers, or storage integrations instead.

lexega-sql 3.0.0 · snowflake · with a key

Same stage, no secret in the SQL. Access goes through a storage integration, so the same stage is allowed.

-- Same stage. Access goes through a storage integration,
-- so no secret appears in the SQL.
CREATE OR REPLACE STAGE raw.vendor_drop
  URL = 's3://acme-vendor-drop/inbound/'
  STORAGE_INTEGRATION = vendor_s3_int;
ALLOWEDAllowed — no critical or high findings

lexega-sql 3.0.0 · snowflake · with a key

Your standards, enforced

Any built-in rule can be raised, lowered, reworded or switched off by naming its ID. These entries make every dynamic SQL execution block a merge, not only the ones traced to untrusted input, and require procedures to run with the caller's rights. Without a key, every query string built by concatenation counts, even one made only of literals or names passed through QUOTENAME(), so those block until someone reviews them. With a key, Lexega reads the pieces, and a string built only from literals and quoted names is listed as context and does not block.

With this file and no key, a procedure that concatenates input into EXEC is critical, and the same procedure passing the input only as a bound sp_executesql parameter is clean. Your own checks are written the same way, as plain YAML.

Custom rules are free. They run on the same engine and see the same facts as the built-in rules. Write your own

appsec-rules.yaml
rules:
  # Any dynamic SQL blocks a merge here, not only what is traced to input.
  - id: PROC-DYNSQL
    risk_level: critical
  - id: DYNSQL
    risk_level: critical
  - id: DYNSQL-NO-PARAM
    risk_level: critical

  # Procedures in our estate run with the caller's rights.
  - id: PROC-EXECAS-OWNER
    risk_level: critical
    message: "Procedures must use EXECUTE AS CALLER."

Built to pass your own review

Runs inside your environment

One program. No account, no telemetry, works without internet access.

Never touches your data

It reads SQL text and never connects to run a query.

Same answer every time

The same SQL and policy always give the same result.

Source you can read

The open edition, lexega, is published on GitHub: the parser, the statement-level analysis and every built-in rule. Tracing across procedures is in the licensed build.

Questions security teams ask

Our scanner already covers SQL.
Check which languages it lists, then run Lexega free on a folder of procedures and compare the results yourself.
Do you have SOC 2?
No. Lexega runs entirely inside your environment, never sees your data, sends nothing to Lexega and checks its license offline.
Will false positives bury us?
Every example on this site has a near-identical safe version that comes back allowed, which shows the rules tell the two apart. Only your own code shows the noise on your code: without a key, every query string a procedure builds by concatenation is reported at high for review; a trial key traces each one, so strings built only from literals and quoted names drop out.
Can we add our own checks, or quiet a noisy one?
Yes, in plain YAML, with no code. Your rules see the same facts as the built-in ones, and any built-in rule can be raised, lowered, reworded or switched off by its ID.
Where do findings go?
To GitHub code scanning as SARIF or to GitLab in its security report format, and to a pull-request comment. Under a policy, each run also writes a decision record you keep.

Run it on a folder of procedures today

Install free, point it at your procedures and upload the SARIF. Without a key, each query string a procedure builds by concatenation is reported for review. A 30-day trial key traces every value to its source, across variables and procedure calls.