Skip to content

fix(ui): derive a session's tenant from its claim as the REST extractor does - #3371

Open
angela-helios wants to merge 2 commits into
mainfrom
fix/2934-ui-tenant-claim-validation
Open

angela-helios wants to merge 2 commits into
mainfrom
fix/2934-ui-tenant-claim-validation

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Closes #2934

Behaviour change to review

  • A browser session whose token carries an empty tenant claim is now bound to the default tenant (it used to be bound to the empty string).
  • A browser session whose verified token carries a malformed or reserved tenant claim (for example __system__) is bound to no tenant. Home and the subscription inventory answer 403 with a new notice (auth-tenant-claim-refused, en/es/de), the tenant selector does not offer the claim, and POST /ui/tenant answers 403 for every choice. This also applies to a session with a system/*.r scope: the scope no longer lets it pick a registered tenant, since the API refuses that token for every tenant.
  • The REST API's answers do not change.

Summary

The web UI took a session's tenant claim as issued, while TenantExtractor::resolve treats an empty claim as no claim and refuses an unparseable or reserved one. The two now share one rule.

  • TenantId::from_claim (helios-persistence) returns no tenant for an absent or empty claim, the tenant for a claim TenantId::parse accepts, and an error otherwise. parse already refuses reserved ids.
  • TenantExtractor::resolve uses it in place of its own empty filter and parse. Status and message are the same as before.
  • The UI's claimed_tenant and tenant_allowed derive the session's tenant through it. A refused claim gives the session no tenant.
  • The session gate stamps the marker it already uses for an unverified token when the claim is refused, so refuse_unverified_tenant_reads and RequestTenant::live_counts cover it. A second marker selects a notice that names the tenant claim rather than token verification.

Not in this change: the claimed tenant is still not checked against the tenant registry, and the administrative pages' system/* gate is unchanged.

Tests

  • helios-persistence: unit tests and a doctest for TenantId::from_claim (absent, empty, valid, reserved, malformed).
  • helios-rest: existing extractors::tenant tests, as the extractor now goes through the shared function.
  • helios-ui login_http.rs: new cases for an empty claim (default tenant, no empty option), a reserved claim, an unparseable claim, and a reserved claim with a system/*.r scope.
  • helios-ui locale key parity for the new key.

Results:

  • cargo test -p helios-persistence --lib with all backend features, filtered to the modules the pending fixes touch (among them error::, tenant::id, backends::sqlite::backend): 1081 passed.
  • cargo test -p helios-rest --lib: 1131 passed.
  • cargo test -p helios-ui --lib: 396 passed. --test login_http: 26 passed. --test i18n_http: 10 passed.
  • I did not run the doctest or clippy locally; CI runs them.

These ran on a branch that also carried other pending fixes, so the suites were verified in combination, not on this branch alone.

…or does

The UI bound a session to its token's tenant claim as issued. An empty
claim became the empty tenant, and a reserved or malformed claim was
used as is, while the API treats the first as claimless and refuses the
others.

TenantId::from_claim now holds the rule and both the REST extractor and
the UI use it. An empty claim falls back to the default tenant. A
refused claim leaves the session with no tenant: the pages that read
tenant state from the process answer 403 and no tenant is selectable.

Closes #2934

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI binds a session to its tenant claim as issued: empty, reserved and invalid claims are not handled as the REST extractor handles them

2 participants