Skip to content

sessions.create() with requestSource.raw doesn't base64-encode the raw field #37

Description

@dedeoglukaan

Description

When creating a replay session from a raw HTTP request using client.replay.sessions.create({ requestSource: { raw, connection } }), the SDK passes the raw string directly to the GraphQL mutation. However, Caido's GraphQL schema expects the raw field inside RequestRawInput to be a Blob type (base64-encoded string).

This causes the following error:

Error: [GraphQL] Expected input type "Blob", found "GET / HTTP/1.1\r\n...". 
(occurred while parsing "RequestRawInput") 
(occurred while parsing "RequestSourceInput") 
(occurred while parsing "CreateReplaySessionInput")

Root Cause

Looking at the SDK source, mapRequestSource() passes requestSource.raw through as-is:

const mapRequestSource = (requestSource) => {
  if ("id" in requestSource) return { id: requestSource.id };
  return { raw: {
    connectionInfo: requestSource.connection,
    raw: requestSource.raw  // <-- not encoded
  }};
};

But replay.send() correctly uses encodeBlob() on the raw field:

raw: encodeBlob(options.raw)

So send() works fine, but sessions.create() with a raw source doesn't.

Workaround

Manual base64 encoding via client.graphql.mutation():

const result = await client.graphql.mutation(CREATE_REPLAY_SESSION_RAW, {
  input: {
    kind: "HTTP",
    requestSource: {
      raw: {
        connectionInfo: { host, port, isTLS: tls },
        raw: Buffer.from(rawRequest).toString("base64"),
      },
    },
  },
});

Environment

  • @caido/sdk-client: 0.4.0
  • Caido: 0.57.0

Expected Behavior

sessions.create({ requestSource: { raw: "GET / HTTP/1.1\r\n...", connection: {...} } }) should automatically base64-encode the raw field before sending to GraphQL, similar to how replay.send() handles it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions