How to Configure Token Schema Policy Contract

Published
Length
3 min read

Luis Felipe Dias

All posts

A token schema policy contract defines the exact fields an identity token must contain. You set it up by writing strict validation rules that check every token before login. Teams use these rules to stop bad tokens from reaching backend databases and internal apps. When an identity provider issues a token, the receiving service checks the structure right away. If a required field is missing or has the wrong type, the service blocks the request. This simple check keeps broken scripts and unautho

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

A token schema policy contract defines the exact fields an identity token must contain. You set it up by writing strict validation rules that check every token before login.

Teams use these rules to stop bad tokens from reaching backend databases and internal apps. When an identity provider issues a token, the receiving service checks the structure right away. If a required field is missing or has the wrong type, the service blocks the request. This simple check keeps broken scripts and unauthorized users out of your core systems.

How a token schema policy contract works in practice

Every identity token carries claims about a user or a machine workload. These claims include the user email, team group, role name, and expiration time. Without a strict contract, an app might accept a token with missing group data. That mistake can grant a developer or an automated job too much power.

A token schema policy contract acts as a strict filter at login time. It checks both human users and automated service accounts before they start a session. You define which claims must exist, what format they follow, and which values are valid. For example, you can require that the audience field matches your exact production database name.

Safe defaults make this setup work well across all your teams. Start by rejecting any token that lacks an expiration timestamp or an issuer name. Next, require a specific group or role claim for every single environment. Do not allow empty strings or wildcard values inside role fields. Keep token lifetimes short so stolen tokens expire within a few minutes. When a token fails any check in the contract, deny the login right away.

How to check rules and close session gaps

Before you turn on strict blocking, run your schema rules in log-only mode. This step lets your team spot valid apps that send old token formats. Review your logs each day to see which claims fail the schema check. Once your identity provider sends clean tokens for all users, switch to strict rejection.

Token Rotation + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You should also audit your token rules whenever team roles or identity providers change. Log every failed token check with the user identity, timestamp, and the missing field name. These audit logs help security teams spot misconfigured apps or active login attacks fast.

Still, a token schema check only runs at the moment a user logs in. Once the token passes the check, the user or app gets an open session. Static token rules cannot see what queries or commands run inside that active session. A valid user with a valid token can still run a bad query by mistake. They might pull thousands of customer emails, phone numbers, or card numbers from a table. To protect live data, you need controls that inspect commands and mask fields like national IDs.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What happens when a token fails the schema check?

The system blocks the login request right away and writes an error to the audit log. The user or service account cannot start a session until the token matches the contract.

Which token claims should every team check first?

Start by checking the issuer, audience, subject, expiration time, and team role claims. These five fields prove who sent the token, who owns it, and when it expires.

Can a token schema contract stop a bad database query?

No, a token contract only checks identity claims when a session starts. You need query-level controls and data masking to stop bad commands or rewrite emails in results.

The query runs. The emails stay hidden.