Skip to content

fix: 401 signature invalid when using --filter with JSON values#13

Open
byshing wants to merge 1 commit into
masterfrom
fix/filter-query-signature-encoding
Open

fix: 401 signature invalid when using --filter with JSON values#13
byshing wants to merge 1 commit into
masterfrom
fix/filter-query-signature-encoding

Conversation

@byshing

@byshing byshing commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

bitmex order list --filter '{"ordStatus":"New"}' returned a 401 Signature not valid, while the same command without --filter worked fine.

Root cause

build_query emits raw query strings without percent-encoding. When reqwest sends the request, it passes the URL through url::Url::parse(), which encodes "%22 (WHATWG query encode set). The HMAC signature was computed over the unencoded form while the server received the encoded form — mismatch.

Fix

Added signing_path() in client.rs which parses the URL through the same url crate before signing, extracting the canonically-encoded path+query. This guarantees the signed string exactly matches what the server receives. Applied to both get_auth and delete.

Test plan

  • New unit tests in client.rs::tests: signing_path_encodes_json_filter_quotes, signing_path_empty_query, signing_path_simple_params_unchanged
  • All existing tests pass (cargo test)
  • Manually verified bitmex order list --filter '{"ordStatus":"New"}' returns results without 401

When a query value contains special characters (e.g. a JSON filter like
{"ordStatus":"New"}), reqwest's url::Url::parse encodes them before
sending (" -> %22). The signature was computed over the raw unencoded
string, causing a server-side mismatch and a 401 Signature not valid.

Add signing_path() which parses the URL through the same url crate to
extract the canonically-encoded path+query, ensuring the signed string
matches what the server receives. Applied to get_auth and delete.
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