diegosouzapw/OmniRoute · error

decodeCredentialBlob: invalid payload — could not parse JSON

Error message

decodeCredentialBlob: invalid payload — could not parse JSON

What it means

Buffer.from(b64, 'base64url').toString('utf8') produced bytes that JSON.parse rejected, so the decoded payload is not valid JSON. The blob passed the charset and prefix checks but its content is corrupted or tampered with.

Solutions

  1. Re-export the blob from the source instance
  2. Verify the paste did not drop characters
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/oauth/credentialBlob.ts:85 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/9e48bf3b29b7db54. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/oauth/credentialBlob.ts:85

 * Throws a descriptive error on any malformed/tampered/unsupported input.
 */
export function decodeCredentialBlob(blob: string): CredentialBlob {
  if (typeof blob !== "string" || !blob.startsWith(CREDENTIAL_BLOB_PREFIX)) {
    throw new Error(
      `decodeCredentialBlob: invalid format — must start with "${CREDENTIAL_BLOB_PREFIX}"`
    );
  }
  const b64 = blob.slice(CREDENTIAL_BLOB_PREFIX.length).trim();
  if (!/^[A-Za-z0-9_-]+$/.test(b64)) {
    throw new Error("decodeCredentialBlob: invalid payload — not base64url");
  }

  let parsed: { v?: unknown; provider?: unknown; tokens?: unknown };
  try {
    const json = Buffer.from(b64, "base64url").toString("utf8");
    parsed = JSON.parse(json);
  } catch {
    throw new Error("decodeCredentialBlob: invalid payload — could not parse JSON");
  }

  if (parsed.v !== CREDENTIAL_BLOB_VERSION) {
    throw new Error(
      `decodeCredentialBlob: unsupported blob version ${String(parsed.v)} (expected ${CREDENTIAL_BLOB_VERSION})`
    );
  }
  if (typeof parsed.provider !== "string" || !parsed.provider.trim()) {
    throw new Error("decodeCredentialBlob: invalid payload — missing provider");
  }
  const tokens = parsed.tokens as CredentialBlobTokens | undefined;
  if (!tokens || typeof tokens !== "object") {
    throw new Error("decodeCredentialBlob: invalid payload — missing tokens");
  }
  if (typeof tokens.access_token !== "string" || !tokens.access_token) {
    throw new Error("decodeCredentialBlob: invalid payload — missing access_token");
  }

View on GitHub (pinned to a179ffed5b)