Register error code 40167 for untrusted client type declarations - #355
Merged
Conversation
lmars
reviewed
Jul 30, 2026
|
|
||
| ## What you should do | ||
|
|
||
| Add the `x-ably-clientType` claim, set to `server`, to the token issued for the client, rather than declaring the client type alongside the token. The claim is signed by the API key that issues the token, which is what makes it trustworthy. If the traffic is not from a server, remove the `clientType=server` declaration instead, or set `clientType=device` explicitly. |
Member
There was a problem hiding this comment.
I think this should mention that the developer needs to be using JWT auth, and link to our docs for how to add claims to a JWT token.
I also think "rather than declaring the client type alongside the token" might not be obvious if the developer used a server-side SDK rather than explicitly setting clientType=server themselves.
Member
Author
There was a problem hiding this comment.
reworded.
(i've added a para on if you're accidentally using a Server SDK for a non-server you should switch to a Device SDK, would like to link to docs on that but I assume they don't exist yet)
SimonWoolf
force-pushed
the
client-type-server-declaration-error
branch
from
July 30, 2026 14:05
eec0911 to
2820494
Compare
lmars
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds error code
40167(untrusted_client_type_declaration), needed by the realtime implementation of PSDR22: Differentiating users from servers for MAU billing.Why a new code
PSDR22 classifies every connection and request as
device(the default) orserver, and this determines whether traffic counts toward MAU and whether it is subject to per-client-ID limits. Because a client must not be able to exempt itself, the trust model differs by auth type:x-ably-clientType=serverclaim is the only trusted declaration. AclientType=serverparam or a-serveragent identifier arriving without the claim is rejected with an actionable error, rather than silently honoured or ignored. That rejection is what this code reports.The rejection is deliberately loud in both directions: it catches an end user attempting to exempt themselves, and equally a server misconfigured onto token auth without the claim.
Why 40167 specifically
Placed in the 4016x family of insufficient-credential errors, next to its closest neighbours:
40161(identified_client_required) is the clientId gate — a different rejection that the same feature also uses.40166(unidentified_client_cannot_modify_own_messages) is about "own" capabilities.Neither fits, and no existing code covers "the credential presented cannot grant the declaration being made". 40167 was free.
Notes
protocol/errors.jsonis regenerated vianpm run generate:errors, not hand-edited.ably/realtimeis not written yet; per the guidelines, message strings should be verified against their source. Happy to add it in a follow-up once that lands.validate:errors,validate:errors-json,format:data:check,markdownlintandjestall pass.🤖 Generated with Claude Code