Skip to content

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
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
Result
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.

setup.sql
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;

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'
);

3. Run a query

query.sql
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
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
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]'
);

Overview

SAML 2.0 decode + XML-DSig / exclusive-C14N signature verification + XSW / Golden-SAML detection, in SQL.

Catalog

Everything saml exposes once attached — read straight from the worker's released build.

saml 1 schema
main 13 functions

SAML decode, signature-verification, and XSW / Golden-SAML detection functions.

Schema examples (9)
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;
Result
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;
Scalar functions
anomalies (msg ANY) 2 examples

Flag XSW (XML Signature Wrapping) / Golden-SAML / structural anomalies as a LIST; empty list = no structural red flag found (not a safety guarantee)

Arguments
msg ANY
A SAML 2.0 message to scan for signature-wrapping and structural attack indicators. Pass the value straight from your column — the worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob.
ReturnsVARCHAR[]
Examples (2)

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;
Link
assertions (msg ANY) 2 examples

Return every assertion as a LIST (idx, id, signed, issuer, subject, in_response_to, parent); UNNEST it (parent reveals wrapping)

Arguments
msg ANY
A SAML 2.0 message to fan out into rows with UNNEST(...) over a column. The worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT of 7 fields[]
STRUCT[] 7 fields
  • idxUINTEGER
  • idVARCHAR
  • signedBOOLEAN
  • issuerVARCHAR
  • subjectVARCHAR
  • in_response_toVARCHAR
  • parentVARCHAR
Examples (2)

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;
Result
idx id subject covering_signature
0 _evil [email protected] NULL
1 _a1 [email protected] 0
Link
attributes (msg ANY) 7 examples

Explode SAML attribute statements to a LIST (statement_idx, name, name_format, friendly_name, value, value_type); UNNEST to long form

Arguments
msg ANY
A SAML 2.0 message to fan out into rows with UNNEST(...) over a column. The worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT of 6 fields[]
STRUCT[] 6 fields
  • statement_idxUINTEGER
  • nameVARCHAR
  • name_formatVARCHAR
  • friendly_nameVARCHAR
  • valueVARCHAR
  • value_typeVARCHAR
Examples (7)

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;
Link
authn (msg ANY) 1 example

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)

Arguments
msg ANY
A SAML 2.0 message whose AuthnStatement to extract. The worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT of 6 fields
STRUCT 6 fields
  • authn_instantTIMESTAMP WITH TIME ZONE
  • session_indexVARCHAR
  • session_not_on_or_afterTIMESTAMP WITH TIME ZONE
  • class_refVARCHAR
  • decl_refVARCHAR
  • authenticating_authorityVARCHAR
Example

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;
Link
b64decode (data ANY) 1 example

Base64-decode a string to bytes (accepts standard and URL-safe alphabets, padded or not); NULL on failure

Arguments
data ANY
The base64-encoded text to decode. Both common base64 alphabets are recognized and padding is optional; input that is not valid base64 yields NULL.
ReturnsBLOB
Example

Decode a base64 SAMLResponse form field to raw bytes.

SELECT saml.main.b64decode('PHNhbWw+');
Link
conditions (msg ANY) 1 example

Extract the assertion Conditions: STRUCT(not_before TIMESTAMPTZ, not_on_or_after TIMESTAMPTZ, audiences LIST, one_time_use BOOL, proxy_restriction_count UINTEGER, proxy_audiences LIST). No 'expired' verdict — compare to now() yourself.

Arguments
msg ANY
A SAML 2.0 message whose assertion Conditions validity window to extract. The worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT of 6 fields
STRUCT 6 fields
  • not_beforeTIMESTAMP WITH TIME ZONE
  • not_on_or_afterTIMESTAMP WITH TIME ZONE
  • audiencesVARCHAR[]
  • one_time_useBOOLEAN
  • proxy_restriction_countUINTEGER
  • proxy_audiencesVARCHAR[]
Example

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;
Link
decode (msg ANY) 1 example

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).

Arguments
msg ANY
The SAML message to decode: raw XML, base64, base64+DEFLATE (HTTP-Redirect), or a URL-encoded wrapper. Content-sniffed automatically; malformed input yields null fields, not an error.
ReturnsSTRUCT of 25 fields
STRUCT 25 fields
  • 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
Example

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;
Link
inflate (data ANY) 1 example

Raw-DEFLATE-inflate bytes to text (HTTP-Redirect binding), bounded against decompression bombs; NULL on failure

Arguments
data ANY
The raw-DEFLATE (or zlib-wrapped) compressed bytes to inflate, e.g. the output of b64decode on a redirect-binding query parameter.
ReturnsVARCHAR
Example

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='));
Link
message_type (msg ANY) 1 example

Root-element discriminator: 'Response', 'AuthnRequest', 'LogoutRequest', 'LogoutResponse', 'Assertion', 'ArtifactResolve', or 'unknown'

Arguments
msg ANY
The SAML message: raw XML, base64, base64+DEFLATE (HTTP-Redirect), or a URL-encoded wrapper. Content-sniffed automatically.
ReturnsVARCHAR
Example

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"/>');
Link
signature (msg ANY) 1 example

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). sig_valid is math against the EMBEDDED cert — trust is your JOIN.

Arguments
msg ANY
A SAML 2.0 message whose outermost XML-DSig signature to check. The worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT of 12 fields
STRUCT 12 fields
  • 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
Example

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;
Link
signatures (msg ANY) 1 example

Return every signature in a SAML message as a LIST (idx, scope, references_id, signed_element, c14n_ok, digest_ok, sig_valid, signer_cert_sha256); UNNEST for the multi-sig view

Arguments
msg ANY
A SAML 2.0 message to fan out into rows with UNNEST(...) over a column. The worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT of 8 fields[]
STRUCT[] 8 fields
  • idxUINTEGER
  • scopeVARCHAR
  • references_idVARCHAR
  • signed_elementVARCHAR
  • c14n_okBOOLEAN
  • digest_okBOOLEAN
  • sig_validBOOLEAN
  • signer_cert_sha256VARCHAR
Example

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;
Link
unwrap (param VARCHAR) 1 example

Unwrap a redirect/POST-binding parameter (URL-decode + base64 + DEFLATE sniff) to its SAML XML text; NULL on failure

Arguments
param VARCHAR
The URL-encoded transport parameter (a SAMLRequest/SAMLResponse query value or POST field) to unwrap to XML text.
ReturnsVARCHAR
Example

Recover the XML from a URL-encoded, base64-wrapped transport parameter.

SELECT saml.main.unwrap('PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6cHJvdG9jb2wiLz4%3D');
Link
well_formed (msg ANY) 2 examples

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.

Arguments
msg ANY
A SAML 2.0 message to triage for well-formedness. It is classified without expanding DTDs or entities, and the worker content-sniffs and normalizes the transport wrapper automatically, whether the message arrived as raw XML or an encoded SAMLResponse blob, so pass the value straight from your column.
ReturnsSTRUCT(ok BOOLEAN, kind VARCHAR, detail VARCHAR)
Examples (2)

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;
Link

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

Uses signaturedecodeanomalies

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.