Skip to content

feat(signal): refuse signals for Longbridge Hong Kong accounts - #645

Merged
hogan-yuan merged 5 commits into
mainfrom
feat/refuse-signals-for-hk
Dec 4, 2026
Merged

hogan-yuan merged 5 commits into
mainfrom
feat/refuse-signals-for-hk

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.
@hogan-yuan
hogan-yuan merged commit 95c9f05 into main Dec 4, 2026
109 of 112 checks passed
@hogan-yuan
hogan-yuan deleted the feat/refuse-signals-for-hk branch December 4, 2026 07:00
@hogan-yuan hogan-yuan mentioned this pull request Dec 4, 2026
hogan-yuan added a commit that referenced this pull request Dec 4, 2026
Bumps all crates to 5.7.0 and moves `## [Unreleased]` to `## [5.7.0] -
2026-12-04`. Also adds the missing changelog entry for #643.

Minor bump: new fields (#642), the HK signals refusal and new path
validation in the HTTP client (#645), and a deprecation (#646). Nothing
removed.

```
#646 chore: deprecate industry_valuation_dist
#645 feat(signal): refuse signals for Longbridge Hong Kong accounts
#642 feat(asset): expose bind_fail_reason on BankCard and the decision times on StockTransferIn
#644 fix(asset): list every stock transfer state when no state filter is given
#643 fix(httpclient): leave X-Api-Key out when an OAuth client has no client ID
```

After merge: push `main` to `release` to publish (crates.io, PyPI, npm,
Maven, C++), then tag `v5.7.0` and publish the GitHub release.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
hogan-yuan added a commit to longbridge/longbridge-terminal that referenced this pull request Dec 5, 2026
Bumps the version to 0.34.0 and takes the SDK from crates.io 5.7.0
(`longbridge = "5.6"` → `"5.7"`). `Cargo.toml` plus the lockfile; no
code changes.

SDK 5.7.0 refuses the signal APIs for Longbridge Hong Kong accounts
inside the HTTP client too (longbridge/openapi#645), on top of the CLI's
own check from #364, and drops the empty `X-Api-Key` sent by token-only
OAuth clients (longbridge/openapi#643).

Minor bump: a command is removed (#365).

```
ce09862 chore(cli): remove `industry-valuation dist` (#365)
756203d cli: Refuse signals for Longbridge Hong Kong accounts (#364)
dd83320 chore: bump scoop manifest to 0.33.0
```

`cargo build` and `cargo test` pass (1031 unit tests plus the
integration targets).

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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