Registry Mirror
Skip to content

Conversation

@hogan-yuan

Copy link
Copy Markdown
Member

Refuses the signals APIs for Longbridge Hong Kong accounts: an access token whose account channel is lb or lb_hk (case-insensitive), or that names no channel or cannot be decoded. Other channels (SG, US, paper trading) and security_facts are unaffected.

  • The check sits in longbridge-httpcli, so SignalContext, SignalContextSync and every binding's raw HttpClient request to /v1/signals or /v1/signals/* are refused before anything is sent. Paths are normalised first (query, percent-encoding, //, . / .., trailing slash).
  • Refused calls return the existing HttpClientError::OpenApi with code -403001 and "signals are not available for this account" — no new error variant, so no semver break.
  • The account-channel parsing moved to longbridge_httpcli::account and 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

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.

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.

1 participant