SAML
Decode SAML 2.0 messages, verify their XML signatures, and flag XSW and Golden-SAML attacks in bulk
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/saml/index.md to help me query SAML with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
See what you can query
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
WITH m AS (SELECT '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_r"><saml:Assertion ID="_evil"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>' AS msg), asr AS (SELECT a.* FROM m, UNNEST(saml.main.assertions(m.msg)) AS _(a)), sig AS (SELECT s.* FROM m, UNNEST(saml.main.signatures(m.msg)) AS _(s)) SELECT asr.idx, asr.id, asr.subject, sig.idx AS covering_signature
FROM asr
LEFT JOIN sig ON sig.references_id = asr.id
ORDER BY asr.idx
| idx | id | subject | covering_signature |
|---|---|---|---|
| 0 | _evil | [email protected] | NULL |
| 1 | _a1 | [email protected] | 0 |
Quick start
Choose where to run SAML, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the release directly
Downloads the latest release for your platform and caches it locally.
ATTACH 'saml' AS saml (
TYPE vgi,
LOCATION 'github-auto://Query-farm/vgi-saml'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'saml' AS saml (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-saml:0.5.0'
);
3. Run a query
WITH m AS (SELECT '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_r"><saml:Assertion ID="_evil"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>' AS msg), asr AS (SELECT a.* FROM m, UNNEST(saml.main.assertions(m.msg)) AS _(a)), sig AS (SELECT s.* FROM m, UNNEST(saml.main.signatures(m.msg)) AS _(s)) SELECT asr.idx, asr.id, asr.subject, sig.idx AS covering_signature
FROM asr
LEFT JOIN sig ON sig.references_id = asr.id
ORDER BY asr.idx
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'saml' AS saml
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
WITH m AS (SELECT '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_r"><saml:Assertion ID="_evil"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>' AS msg), asr AS (SELECT a.* FROM m, UNNEST(saml.main.assertions(m.msg)) AS _(a)), sig AS (SELECT s.* FROM m, UNNEST(saml.main.signatures(m.msg)) AS _(s)) SELECT asr.idx, asr.id, asr.subject, sig.idx AS covering_signature
FROM asr
LEFT JOIN sig ON sig.references_id = asr.id
ORDER BY asr.idx
Query Farm operates SAML for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use saml as the catalog alias for the query below.
4. Run a query
WITH m AS (SELECT '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_r"><saml:Assertion ID="_evil"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>' AS msg), asr AS (SELECT a.* FROM m, UNNEST(saml.main.assertions(m.msg)) AS _(a)), sig AS (SELECT s.* FROM m, UNNEST(saml.main.signatures(m.msg)) AS _(s)) SELECT asr.idx, asr.id, asr.subject, sig.idx AS covering_signature
FROM asr
LEFT JOIN sig ON sig.references_id = asr.id
ORDER BY asr.idx
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the release directly
Uses the verified release each time you attach the connector.
ATTACH 'saml' AS saml (
TYPE vgi,
LOCATION 'github-auto://Query-farm/[email protected]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'saml' AS saml (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-saml:0.5.0'
);
Overview
SAML 2.0 decode + XML-DSig / exclusive-C14N signature verification + XSW / Golden-SAML detection, in SQL.
Shred and security-check SAML 2.0 single-sign-on messages directly in DuckDB. The saml worker base64-decodes (and, for the HTTP-Redirect binding, raw-DEFLATE inflates) a column of SAMLResponse blobs, decodes them into typed rows — subject, issuer, audience, the Conditions validity window, AuthnContext, and attribute statements — and, more importantly, runs the XML-DSig structural check the one-off tools only do one message at a time: exclusive XML canonicalization (xml-exc-c14n#), per-Reference digest verification, and signature math (RSA / ECDSA / EdDSA) against the embedded certificate.
The defensible value is bulk security compute: running XML Signature Wrapping (XSW) and Golden-SAML detection across millions of historical SAML messages in a forensic lake — in SQL, joinable against your IdP cert inventory and login telemetry. The worker flags the structural invariants every XSW1-XSW8 attack violates (multiple assertions, a signature that covers a different element than the consumer reads, duplicate/dangling reference IDs, an unsigned assertion inside a signed response, comment-splitting NameIDs, digest mismatches), and surfaces the signer certificate SHA-256 fingerprint so a left join against your known-good IdP certs surfaces the Golden-SAML smoking gun (a cryptographically perfect signature from a key you do not trust).
Trust stays with you. sig_valid = true means the embedded cert signed these bytes — never that the cert is authorized. The worker holds no private keys, no trust store, makes no network calls, and decrypts nothing; an EncryptedAssertion is counted and flagged, not opened. All decode and canonicalization is local CPU on bytes you already hold, so it is safe for air-gapped / regulated forensic data.
Hardened against hostile input. Every blob is attacker-controlled, so the XML loader rejects DTDs and entities unparsed (defeating XXE and billion-laughs/exponential-entity-expansion), bounds document size and inflate ratio (DEFLATE-bomb guard), and never panics — a hostile message returns an error verdict, it does not crash the scan. A well-formedness triage verdict reports the reason, and its dtd-present / entity-blocked kinds double as XXE and billion-laughs signals.
When to reach for it. Use it whenever you already hold a column of raw or encoded SAML messages and need to shred, verify, or threat-hunt over them at warehouse scale rather than one message at a time in a browser plugin. The signer certificate SHA-256 fingerprint left-joins against your IdP cert inventory, and decoded NameIDs can be scrubbed before sharing extracts when the source data is sensitive.
Sources and references
- OASIS SAML V2.0 standard — the core assertion/protocol schemas and the HTTP-Redirect / HTTP-POST bindings the decoder follows.
- W3C XML Signature Syntax and Processing 1.1 — the XML-DSig
Signature/SignedInfo/Referencemodel that is verified. - W3C Exclusive XML Canonicalization 1.0 — the
xml-exc-c14n#transform applied before digesting and signature checks.
Catalog
Everything saml exposes once attached — read straight from the worker's
released build.
main 13 functions
SAML decode, signature-verification, and XSW / Golden-SAML detection functions.
Schema examples (9)
Identify a SAML message by its root element.
SELECT saml.main.message_type('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>') AS kind;
Triage why a blob is not a usable SAML message.
SELECT (saml.main.well_formed('not a saml message')).kind AS kind;
Decode an assertion and read its issuer.
SELECT (saml.main.decode('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer></saml:Assertion>')).issuer AS issuer;
Base64-decode a SAMLResponse POST field to text.
SELECT saml.main.b64decode('PHNhbWw+')::VARCHAR AS decoded;
5 more examples
Count the structural anomaly flags on a message.
SELECT len(saml.main.anomalies('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"/>')) AS n;
XSW coverage check: list every assertion in a Response next to the signature (if any) whose Reference points at it; the wrapped evil assertion _evil shows no covering signature.
WITH m AS (SELECT '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_r"><saml:Assertion ID="_evil"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>' AS msg), asr AS (SELECT a.* FROM m, UNNEST(saml.main.assertions(m.msg)) AS _(a)), sig AS (SELECT s.* FROM m, UNNEST(saml.main.signatures(m.msg)) AS _(s)) SELECT asr.idx, asr.id, asr.subject, sig.idx AS covering_signature
FROM asr
LEFT JOIN sig ON sig.references_id = asr.id
ORDER BY asr.idx;
| idx | id | subject | covering_signature |
|---|---|---|---|
| 0 | _evil | [email protected] | NULL |
| 1 | _a1 | [email protected] | 0 |
Triage a batch of blobs before decoding: well_formed classifies each one, and only the usable messages are passed on to message_type and decode for their issuer.
SELECT t.blob_id, (saml.main.well_formed(t.blob)).kind AS triage,
CASE WHEN (saml.main.well_formed(t.blob)).ok THEN saml.main.message_type(t.blob) END AS msg_type,
CASE WHEN (saml.main.well_formed(t.blob)).ok THEN (saml.main.decode(t.blob)).issuer END AS issuer
FROM (VALUES (1, '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer></saml:Assertion>'), (2, 'not a saml message'), (3, '<!DOCTYPE x [<!ENTITY e SYSTEM "file:///etc/passwd">]><samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>')) AS t(blob_id, blob)
ORDER BY t.blob_id;
Per-login security verdict: who each message claims to be (decode), whether it carries a signature (signature), and which structural flags fire (anomalies); login-1 is signed but its digest does not match (digest-mismatch), login-2 is unsigned and carries two assertions (multiple-assertions).
WITH logins AS (SELECT * FROM (VALUES ('login-1', '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion>'), ('login-2', '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_r"><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a2"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>')) AS v(login_id, msg)) SELECT login_id, (saml.main.decode(msg)).subject AS subject, (saml.main.signature(msg)).signed AS signed, saml.main.anomalies(msg) AS flags
FROM logins
ORDER BY login_id;
Roll a multi-valued role attribute up per subject: decode supplies the NameID and the attributes fan-out supplies each role value.
WITH m AS (SELECT '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject><saml:AttributeStatement><saml:Attribute Name="role"><saml:AttributeValue>admin</saml:AttributeValue><saml:AttributeValue>user</saml:AttributeValue></saml:Attribute><saml:Attribute Name="dept"><saml:AttributeValue>finance</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>' AS msg) SELECT (saml.main.decode(m.msg)).subject AS subject, list_sort(list(a.value)) AS roles
FROM m,
UNNEST(saml.main.attributes(m.msg)) AS _(a)
WHERE a.name = 'role'
GROUP BY ALL
ORDER BY subject;
anomalies (msg ANY)
Flag XSW (XML Signature Wrapping) / Golden-SAML / structural anomalies as a LIST
Surface signature-wrapping / structural red flags (here, multiple-assertions) for a message.
SELECT saml.main.anomalies('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:Assertion ID="_a1"/><saml:Assertion ID="_a2"/></samlp:Response>');
Per-login security verdict: who each message claims to be (decode), whether it carries a signature (signature), and which structural flags fire (anomalies); login-1 is signed but its digest does not match (digest-mismatch), login-2 is unsigned and carries two assertions (multiple-assertions).
WITH logins AS (SELECT * FROM (VALUES ('login-1', '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion>'), ('login-2', '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_r"><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a2"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>')) AS v(login_id, msg)) SELECT login_id, (saml.main.decode(msg)).subject AS subject, (saml.main.signature(msg)).signed AS signed, saml.main.anomalies(msg) AS flags
FROM logins
ORDER BY login_id;
assertions (msg ANY)
Return every assertion as a LIST
-
idxUINTEGER
-
idVARCHAR
-
signedBOOLEAN
-
issuerVARCHAR
-
subjectVARCHAR
-
in_response_toVARCHAR
-
parentVARCHAR
Enumerate assertions and their parents to reveal wrapping.
SELECT a.idx, a.id, a.parent
FROM UNNEST(saml.main.assertions('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:Assertion ID="_a1"/></samlp:Response>')) AS _(a)
ORDER BY a.idx;
XSW coverage check: list every assertion in a Response next to the signature (if any) whose Reference points at it; the wrapped evil assertion _evil shows no covering signature.
WITH m AS (SELECT '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_r"><saml:Assertion ID="_evil"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>' AS msg), asr AS (SELECT a.* FROM m, UNNEST(saml.main.assertions(m.msg)) AS _(a)), sig AS (SELECT s.* FROM m, UNNEST(saml.main.signatures(m.msg)) AS _(s)) SELECT asr.idx, asr.id, asr.subject, sig.idx AS covering_signature
FROM asr
LEFT JOIN sig ON sig.references_id = asr.id
ORDER BY asr.idx;
| idx | id | subject | covering_signature |
|---|---|---|---|
| 0 | _evil | [email protected] | NULL |
| 1 | _a1 | [email protected] | 0 |
attributes (msg ANY)
Explode SAML attribute statements to a LIST
-
statement_idxUINTEGER
-
nameVARCHAR
-
name_formatVARCHAR
-
friendly_nameVARCHAR
-
valueVARCHAR
-
value_typeVARCHAR
Explode a multi-valued attribute to long form (one row per value).
SELECT a.name, a.value
FROM UNNEST(saml.main.attributes('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:AttributeStatement><saml:Attribute Name="role"><saml:AttributeValue>admin</saml:AttributeValue><saml:AttributeValue>user</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>')) AS _(a)
ORDER BY a.value;
Roll a multi-valued role attribute up per subject: decode supplies the NameID and the attributes fan-out supplies each role value.
WITH m AS (SELECT '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject><saml:AttributeStatement><saml:Attribute Name="role"><saml:AttributeValue>admin</saml:AttributeValue><saml:AttributeValue>user</saml:AttributeValue></saml:Attribute><saml:Attribute Name="dept"><saml:AttributeValue>finance</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>' AS msg) SELECT (saml.main.decode(m.msg)).subject AS subject, list_sort(list(a.value)) AS roles
FROM m,
UNNEST(saml.main.attributes(m.msg)) AS _(a)
WHERE a.name = 'role'
GROUP BY ALL
ORDER BY subject;
SELECT saml.main.message_type('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>') AS kind;
4 more examples
SELECT (saml.main.well_formed('not a saml message')).kind AS kind;
SELECT saml.main.b64decode('PHNhbWw+')::VARCHAR AS decoded;
SELECT list_contains(saml.main.anomalies('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_r"><saml:Assertion ID="_a1"/><saml:Assertion ID="_a2"/></samlp:Response>'), 'multiple-assertions') AS has_multi;
SELECT a.value AS value
FROM UNNEST(saml.main.attributes('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:AttributeStatement><saml:Attribute Name="role"><saml:AttributeValue>admin</saml:AttributeValue><saml:AttributeValue>user</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion>')) AS _(a)
ORDER BY a.value;
authn (msg ANY)
Extract the AuthnStatement + AuthnContext: STRUCT(authn_instant TIMESTAMPTZ, session_index VARCHAR, session_not_on_or_after TIMESTAMPTZ, class_ref VARCHAR, decl_ref VARCHAR, authenticating_authority VARCHAR)
-
authn_instantTIMESTAMP WITH TIME ZONE
-
session_indexVARCHAR
-
session_not_on_or_afterTIMESTAMP WITH TIME ZONE
-
class_refVARCHAR
-
decl_refVARCHAR
-
authenticating_authorityVARCHAR
Read the AuthnContext class (e.g. detect MFA downgrade).
SELECT (saml.main.authn('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:AuthnStatement><saml:AuthnContext><saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef></saml:AuthnContext></saml:AuthnStatement></saml:Assertion>')).class_ref;
b64decode (data ANY)
Base64-decode a string to bytes (accepts standard and URL-safe alphabets, padded or not); NULL on failure
Decode a base64 SAMLResponse form field to raw bytes.
SELECT saml.main.b64decode('PHNhbWw+');
conditions (msg ANY)
Extract the assertion Conditions: STRUCT(not_before TIMESTAMPTZ, not_on_or_after TIMESTAMPTZ, audiences LIST
-
not_beforeTIMESTAMP WITH TIME ZONE
-
not_on_or_afterTIMESTAMP WITH TIME ZONE
-
audiencesVARCHAR[]
-
one_time_useBOOLEAN
-
proxy_restriction_countUINTEGER
-
proxy_audiencesVARCHAR[]
Read the assertion validity window for an own-skew expiry check.
SELECT (saml.main.conditions('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:Conditions NotBefore="2026-01-01T00:00:00Z" NotOnOrAfter="2026-01-01T01:00:00Z"/></saml:Assertion>')).not_on_or_after;
decode (msg ANY)
Decode a SAML message (raw XML / base64 / base64+DEFLATE / URL-encoded) to a STRUCT of core fields: subject, issuer, audience, conditions window, authn_context, status, ids, counts, and signed. Never errors on bad input — returns null fields + signed=false (see well_formed).
-
message_typeVARCHAR
-
response_idVARCHAR
-
assertion_idVARCHAR
-
issuerVARCHAR
-
subjectVARCHAR
-
subject_formatVARCHAR
-
subject_sp_qualifierVARCHAR
-
confirmation_methodVARCHAR
-
recipientVARCHAR
-
in_response_toVARCHAR
-
subject_not_on_or_afterTIMESTAMP WITH TIME ZONE
-
not_beforeTIMESTAMP WITH TIME ZONE
-
not_on_or_afterTIMESTAMP WITH TIME ZONE
-
audienceVARCHAR
-
audiencesVARCHAR[]
-
authn_instantTIMESTAMP WITH TIME ZONE
-
session_indexVARCHAR
-
authn_contextVARCHAR
-
statusVARCHAR
-
destinationVARCHAR
-
issue_instantTIMESTAMP WITH TIME ZONE
-
versionVARCHAR
-
assertion_countUINTEGER
-
encrypted_countUINTEGER
-
signedBOOLEAN
Decode a SAML assertion to its subject + core fields.
SELECT (saml.main.decode('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion>')).subject;
inflate (data ANY)
Raw-DEFLATE-inflate bytes to text (HTTP-Redirect binding), bounded against decompression bombs; NULL on failure
Base64-decode then raw-DEFLATE-inflate a redirect-binding SAMLRequest to its XML text.
SELECT saml.main.inflate(saml.main.b64decode('sylOzM0psHIsLcnIC0otLE0tLlGoyM3JK7YCS9gqlRblWeUnFmcWW+Ul5qYWW5UkWwU7+vpYGekZWBUU5ZfkJ+fnKCl4utgqxRcZKunbAQA='));
message_type (msg ANY)
Root-element discriminator: 'Response', 'AuthnRequest', 'LogoutRequest', 'LogoutResponse', 'Assertion', 'ArtifactResolve', or 'unknown'
Identify the kind of a SAML message from its root element.
SELECT saml.main.message_type('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>');
signature (msg ANY)
Verify the outermost XML-DSig signature: STRUCT(signed, c14n_ok, digest_ok, sig_valid, algo, c14n_method, digest_method, signer_cert BLOB, signer_cert_sha256, signer_subject, signer_issuer, references LIST
-
signedBOOLEAN
-
c14n_okBOOLEAN
-
digest_okBOOLEAN
-
sig_validBOOLEAN
-
algoVARCHAR
-
c14n_methodVARCHAR
-
digest_methodVARCHAR
-
signer_certBLOB
-
signer_cert_sha256VARCHAR
-
signer_subjectVARCHAR
-
signer_issuerVARCHAR
-
referencesSTRUCT[]STRUCT[] 4 fields
-
uriVARCHAR
-
digest_methodVARCHAR
-
digest_okBOOLEAN
-
resolved_elementVARCHAR
-
Check whether a SAML message's embedded signature is internally valid (false here — the assertion is unsigned).
SELECT (saml.main.signature('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer></saml:Assertion>')).sig_valid;
signatures (msg ANY)
Return every signature in a SAML message as a LIST
-
idxUINTEGER
-
scopeVARCHAR
-
references_idVARCHAR
-
signed_elementVARCHAR
-
c14n_okBOOLEAN
-
digest_okBOOLEAN
-
sig_validBOOLEAN
-
signer_cert_sha256VARCHAR
Enumerate every signature and its scope to spot wrapping.
SELECT s.idx, s.scope, s.sig_valid
FROM UNNEST(saml.main.signatures('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a1"/></ds:SignedInfo></ds:Signature><saml:Assertion ID="_a1"/></samlp:Response>')) AS _(s)
ORDER BY s.idx;
unwrap (param VARCHAR)
Unwrap a redirect/POST-binding parameter (URL-decode + base64 + DEFLATE sniff) to its SAML XML text; NULL on failure
Recover the XML from a URL-encoded, base64-wrapped transport parameter.
SELECT saml.main.unwrap('PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiLz4%3D');
well_formed (msg ANY)
Triage a SAML blob into STRUCT(ok BOOL, kind VARCHAR, detail VARCHAR); kind is one of ok / not-xml / not-saml / bad-base64 / bad-deflate / dtd-present / entity-blocked / truncated / encoding-error. Never panics.
Classify why a blob is not a usable SAML message (kind = 'bad-base64' here: text that is not XML is sniffed as a base64 transport wrapper).
SELECT (saml.main.well_formed('not a saml message')).kind;
Triage a batch of blobs before decoding: well_formed classifies each one, and only the usable messages are passed on to message_type and decode for their issuer.
SELECT t.blob_id, (saml.main.well_formed(t.blob)).kind AS triage,
CASE WHEN (saml.main.well_formed(t.blob)).ok THEN saml.main.message_type(t.blob) END AS msg_type,
CASE WHEN (saml.main.well_formed(t.blob)).ok THEN (saml.main.decode(t.blob)).issuer END AS issuer
FROM (VALUES (1, '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer></saml:Assertion>'), (2, 'not a saml message'), (3, '<!DOCTYPE x [<!ENTITY e SYSTEM "file:///etc/passwd">]><samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>')) AS t(blob_id, blob)
ORDER BY t.blob_id;
Try these queries
Identify a SAML message by its root element.
SELECT saml.main.message_type('<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"/>') AS kind
Uses message_type
Triage why a blob is not a usable SAML message.
SELECT (saml.main.well_formed('not a saml message')).kind AS kind
Uses well_formed
Decode an assertion and read its issuer.
SELECT (saml.main.decode('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer></saml:Assertion>')).issuer AS issuer
Uses decode
Base64-decode a SAMLResponse POST field to text.
SELECT saml.main.b64decode('PHNhbWw+')::VARCHAR AS decoded
Uses b64decode
Count the structural anomaly flags on a message.
SELECT len(saml.main.anomalies('<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"/>')) AS n
Uses anomalies
Per-login security verdict: who each message claims to be (decode), whether it carries a signature (signature), and which structural flags fire (anomalies); login-1 is signed but its digest does not match (digest-mismatch), login-2 is unsigned and carries two assertions (multiple-assertions).
WITH logins AS (SELECT * FROM (VALUES ('login-1', '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" ID="_a"><saml:Issuer>https://idp.example.com</saml:Issuer><ds:Signature><ds:SignedInfo><ds:Reference URI="#_a"/></ds:SignedInfo></ds:Signature><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion>'), ('login-2', '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_r"><saml:Assertion ID="_a1"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion><saml:Assertion ID="_a2"><saml:Issuer>https://idp.example.com</saml:Issuer><saml:Subject><saml:NameID>[email protected]</saml:NameID></saml:Subject></saml:Assertion></samlp:Response>')) AS v(login_id, msg)) SELECT login_id, (saml.main.decode(msg)).subject AS subject, (saml.main.signature(msg)).signed AS signed, saml.main.anomalies(msg) AS flags
FROM logins
ORDER BY login_id
17 more examples in the Catalog, each listed under the table or function it uses.
SAML is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Disassembler
Security & forensics
Disassemble binaries and shellcode, then triage their sections, imports, strings, and MITRE ATT&CK capabilities
Windows event logs (EVTX)
Security & forensics
Parse Windows .evtx event-log files into queryable SQL rows for forensics and incident response
NTFS MFT
Security & forensics
Turn a collected NTFS $MFT into a SQL forensic timeline with full paths, timestomp flags, deleted records, and data streams