Conversation
SignalContext::signals and SignalContext::signal (and the blocking SignalContextSync equivalents) now fail with the new Error::NotAvailableForAccount before any request is sent when the access token belongs to a Longbridge Hong Kong account: account channel lb or lb_hk (case-insensitive, trimmed), or a token that names no channel or cannot be decoded. Other channels and security_facts are unaffected. The account-channel decoding moves from asset/token.rs to a shared crate::token module, which gains is_hong_kong_account.
Address review of the Hong Kong signals restriction: - Drop the new Error::NotAvailableForAccount variant (a semver break). The refusal is now HttpClientError::OpenApi with the SDK-local code SIGNALS_NOT_AVAILABLE_CODE (-403001; server business codes are positive) and the neutral message "signals are not available for this account", which every binding already maps to its code/message. - Refuse in longbridge-httpcli's request building, so SignalContext, SSE requests and the raw HttpClient of every binding are covered. The request path is normalized first (query and fragment dropped, percent-decoding, repeated/trailing slashes, `.`/`..` segments, case). SignalContext's own check is removed as redundant. - Move the account-channel parsing to longbridge_httpcli::account; the token payload may be base64url or standard base64, padded or not. - Shared token samples (test-util feature) drive the httpcli and SignalContext tests, including OAuth sessions and send_events.
- is_signals_path refuses when the raw path or any percent-decoded form
(decoded until stable, at most five times) addresses /v1/signals, so
`/v1/signals/x%2F..%2F..` (sent with the signals prefix) is refused.
- Normalize each form as the URL parser does: drop tabs, line feeds and
carriage returns, read `\` as `/`, treat `%2e` as a dot and ignore
`;` parameters.
- SignalContext::signals/signal again refuse a Hong Kong account before
looking at the path, alongside the HTTP client check, so
signal("x/../..") is refused too.
- The message now says there is no alternative and not to retry; the
code stays -403001. HttpClientError::signals_not_available() and
SIGNALS_NOT_AVAILABLE_MESSAGE are exported.
- Shared path samples drive the matcher and the HTTP client tests.
The request URL was the base URL and the path joined as a string, while the check only looked at the path given, so `:443/v1/signals` or `@openapi.longbridge.com/v1/signals` passed the check yet requested /v1/signals, and `/v1/signals/..;/x` was read as `..` by the path normalization but kept as is by the URL parser. - Join and parse the request URL first. A path that does not start with `/`, a URL that does not parse, or one addressing another scheme, host, port or user than the base URL is refused for every account with the new HttpClientError::InvalidRequestPath, before anything is sent. - account::is_signals_request refuses when the parsed URL path, or any percent-decoded form of it, is /v1/signals or under /v1/signals/ (ignoring case), or when the existing normalization matches either the URL path or the path given. The normalization is kept as an extra check: any match refuses. - The message is now "signals are not available for this account. There is no alternative; do not retry." (code -403001 unchanged). - Tests with a counting local server: the new bypass paths are refused with no request sent, earlier shared samples stay refused, other paths are sent, for both API key and OAuth.
…or-hk # Conflicts: # CHANGELOG.md
This branch has not been deployed
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.
Refuses the signals APIs for Longbridge Hong Kong accounts: an access token whose account channel is
lborlb_hk(case-insensitive), or that names no channel or cannot be decoded. Other channels (SG, US, paper trading) andsecurity_factsare unaffected.longbridge-httpcli, soSignalContext,SignalContextSyncand every binding's rawHttpClientrequest to/v1/signalsor/v1/signals/*are refused before anything is sent. Paths are normalised first (query, percent-encoding,//,./.., trailing slash).HttpClientError::OpenApiwith code-403001and "signals are not available for this account" — no new error variant, so no semver break.longbridge_httpcli::accountand accepts base64url and standard base64, padded or not.This is a client-side guard; the gateway does not enforce it yet.
🤖 Generated with Claude Code