TL;DR: treat a social login as proof of who started a session, never as permission to export a tenant record. For a property-management system, the export path should load a current consent category, bind the decision to the authenticated subject and requested fields, and append an audit event before bytes leave the service. If any of those checks cannot be made, fail closed and ask for a fresh authorization step.
A leasing coordinator may sign in with Google while an owner uses GitHub. Their identity providers differ, but the dangerous boundary is the same: a valid session can still be asking for a data release that the tenant never allowed. I model that boundary as seven gates because a single boolean such as consent=true hides too many failure modes.
Hard stop.
How should a property manager check consent category before exporting tenant records?
The decision record has four invariants. The subject must be bound to a verified account identifier, the consent record must be current and scoped to the requested category, the export must have a bounded purpose and field set, and an immutable audit event must be accepted before the response stream opens. These are invariants, not suggestions for a happy path.
The failure boundary sits between authorization and serialization. Authentication establishes a session; authorization decides whether this particular subject may release this particular data now. A provider callback can be replayed, a browser can retain an old session, and a consent row can be revoked while a long-running export is queued. The export worker therefore rechecks the decision immediately before reading sensitive rows.
| Gate | Question | Closed response |
|---|---|---|
| 1. Session | Is the session tied to the expected account and recent enough for this action? | Require reauthentication or reject |
| 2. Subject | Does the account map to exactly one tenant or staff principal? | Reject ambiguous mapping |
| 3. Category | Does an active consent grant cover the requested category? | Return a policy denial |
| 4. Purpose | Is the declared purpose allowed for this role and workflow? | Stop before query planning |
| 5. Scope | Are fields, date range, and recipient within the grant? | Narrow or reject |
| 6. Audit | Can the service append a durable decision event? | Fail closed |
| 7. Delivery | Is the artifact encrypted, time-limited, and single-use? | Do not issue a link |
A table is useful here because the gates have different owners. The identity layer can tell me that an account authenticated; only the policy layer can tell me that a lease ledger or maintenance history is releasable. Mixing those answers is how a harmless profile export grows into a legal and operational incident.
How do Google and GitHub sign-ins change the consent check?
They change the input normalization, not the decision rule. The callback handler should validate the authorization response according to the provider's protocol, verify the issuer and audience where applicable, and map the result to an internal principal. Store the provider subject as an opaque identifier. An email address is useful for display and account linking, but it is a poor primary key for a release decision because it can change or be reused.
After mapping, issue a server-side session with a short idle timeout for staff actions. Set cookies with Secure, HttpOnly, and an appropriate SameSite value; rotate the session identifier after login and privilege changes. OWASP's authentication guidance treats session management and reauthentication as separate controls, which is the distinction an export endpoint needs.
The consent service should receive a normalized request such as (principal_id, tenant_id, category, purpose, fields, recipient). It should return a decision object containing the policy version, consent record identifier, expiration, and a reason code. OAuth 2.0 and PKCE protect the authorization exchange, but neither standard grants permission to release a tenant record. Do not pass a provider token into the export worker. That token proves something about the login exchange; it does not describe the tenant's sharing choice.
Here is the critical path in Python-like pseudocode. The same ordering applies inside an Express handler and its queue consumer; the language is incidental, while the order is the control.
from datetime import datetime, timezone
def authorize_export(session, request, consent_store, audit_log):
now = datetime.now(timezone.utc)
principal = require_recent_session(session, max_age_seconds=900)
tenant = resolve_single_tenant(principal, request.tenant_id)
policy = consent_store.current(tenant.id, request.category, now)
if not policy or request.purpose not in policy.purposes:
raise PolicyDenied("consent_category_or_purpose")
if not policy.allows_fields(request.fields):
raise PolicyDenied("field_scope")
if request.recipient not in policy.recipients:
raise PolicyDenied("recipient_scope")
event = {
"event": "tenant_export_authorized",
"principal_id": principal.id,
"tenant_id": tenant.id,
"category": request.category,
"purpose": request.purpose,
"policy_version": policy.version,
"consent_id": policy.consent_id,
"occurred_at": now.isoformat(),
}
audit_log.append_durable(event)
return ExportGrant(tenant.id, request.fields, expires_in=300)
The audit append precedes the grant.
If the log is unavailable, the service has no evidence that it made the decision and should not release data. Include a correlation ID and a hash of the eventual artifact in a second event when delivery completes; never put raw tenant notes or access tokens in the audit payload. That extra event gives an incident reviewer a clean boundary between permission to build an artifact and permission to retrieve it, even when a worker retries after a 300-second grant has expired.
Which failure modes deserve a hard stop?
The common mistake is checking consent once in the web request and trusting the queue forever.
A revoked grant then remains effective until a worker finishes. Recheck at dequeue time, and attach a short expiry to the grant so a stalled job cannot become a permanent capability.
Another trap is account linking by email alone. A staff member can have a provider account with an address that matches a tenant's address, or an organization can later recycle a mailbox. Require an explicit, authenticated linking flow and preserve both provider subject and internal principal in the audit trail.
A third failure is partial export. If the process writes a ZIP file and discovers a denied category halfway through, deleting the filename is not enough; temporary storage, access logs, and CDN caches may still contain fragments. Build the artifact in an isolated location, commit it only after authorization, encrypt it with a key whose access is logged, and issue a one-time, short-lived retrieval token.
I also reject “soft success” responses that return an empty array for a denied category. Callers interpret that as no records and may cache it. Return a stable policy error with a correlation ID, while keeping the user-facing message free of sensitive policy details.
When is a simpler design acceptable?
A single synchronous check can be valid for a small, non-sensitive export when the response is generated in memory, the consent record is strongly consistent, and the audit append is on the same transaction path. It is easier to operate and easier to explain during an incident.
That design stops being adequate once exports are queued, cross tenant boundaries, or include documents. At that point, the capability object and worker recheck are worth their complexity. I would reject a design that relies on eventual cache invalidation for revocation, even if its median latency looks excellent; a five-minute stale grant is a policy violation, not a performance trade-off.
Before launch, test the negative paths as first-class behavior: revoked consent between enqueue and dequeue, a provider subject mapped to two principals, an audit store timeout, a changed field list, and a replayed download token. Record policy version and reason codes in metrics, but keep labels bounded so a tenant ID cannot explode cardinality. Alert on denial spikes and on any export completion without a preceding authorization event.
The decision rule is deliberately dull: authenticate with the provider that fits the organization, then make every release stand on its own consent, scope, and evidence. That separation preserves login convenience without letting a familiar button become an unrestricted data channel.
Top comments (0)