Skip to content

initUpload/storeChunk cast a missing cryptifytoken header to string #120

Description

@dobby-coder

Both places where the SDK reads Cryptify's rolling upload token cast a possibly-null header to string:

  • src/api/cryptify.ts:122initUpload: const token = response.headers.get('cryptifytoken') as string;
  • src/api/cryptify.ts:222storeChunk: same cast

Headers.get() returns null when the header is absent. The most likely way that happens in a browser is a Cryptify deployment (or a proxy in front of it) that doesn't list cryptifytoken in Access-Control-Expose-Headers — the response is a 200, but the header is invisible to the SDK.

What the caller sees today: state.token becomes null, the next chunk PUT sends cryptifytoken: null as a literal string, and Cryptify rejects it with a token mismatch. The surfaced error points at chunk upload, several steps away from the actual cause. The same silent null can also be written into a FileState the consumer persists for resumeUpload.

Fix: after each headers.get('cryptifytoken'), throw a NetworkError naming the missing header and the CORS-exposure cause instead of casting. Add unit tests in tests/api.test.ts for a 200 init response and a 200 chunk response that carry no cryptifytoken header.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions