Skip to content

fix(carto): only attach Authorization header when accessToken is present#10373

Open
jatorre wants to merge 1 commit into
visgl:masterfrom
jatorre:fix/carto-conditional-auth-header
Open

fix(carto): only attach Authorization header when accessToken is present#10373
jatorre wants to merge 1 commit into
visgl:masterfrom
jatorre:fix/carto-conditional-auth-header

Conversation

@jatorre

@jatorre jatorre commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Background

TilejsonResult.accessToken is becoming optional in @carto/api-client (CartoDB/carto-api-client#298 adds a session auth mode where requests are authenticated by a same-origin session cookie behind a proxy, and no token ever reaches JavaScript — tile URLs come back rewritten onto the proxy base).

Today the CARTO tile layers and fetchMap's createLoadOptions build Authorization: Bearer ${tileJSON.accessToken} unconditionally, so a missing token produces the literal header Bearer undefined — which actively breaks cookie-session servers (they engage only when the Authorization header is absent) and sends a junk credential otherwise.

Change List

  • New getAuthFetchOptions(accessToken?) helper in modules/carto/src/utils.ts: returns the Bearer header when a token is present, or {credentials: 'same-origin'} when not (so the cookie rides along on same-origin tile requests).
  • Used at the 6 existing header sites: vector / h3 / quadbin / raster / cluster tile layers (getLoadOptions) and createLoadOptions in parse-map.ts (param widened to string | undefined).
  • No behavior change when a token is present (the default and existing path).

Verified: carto module suite green (28 files / 124 tests), monorepo lint 0 errors, prettier clean.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23430ad9ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

credentials?: RequestCredentials;
} {
if (!accessToken) {
return {credentials: 'same-origin'};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve caller-supplied fetch credentials

When accessToken is absent, every CARTO tile layer passes this object into mergeLoadOptions(super.getLoadOptions(), ...); because credentials is a primitive value, it overwrites any loadOptions.fetch.credentials the application supplied. This breaks configurations that intentionally use credentials: 'include' for cross-origin cookie auth or credentials: 'omit' for public requests, even though the intended fix only needs to omit the Authorization header. Returning an empty fetch-options object in the no-token case would avoid clobbering user fetch settings.

Useful? React with 👍 / 👎.

@jatorre

jatorre commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@felixpalmer hey mate. Could you take a look?

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