Skip to content

🎯 fix: Narrow Public Share 401 Bypass to the Share Endpoint Only - #12905

Merged
danny-avila merged 1 commit into
devfrom
codex-fix-public-share-redirect
Jun 20, 2026
Merged

🎯 fix: Narrow Public Share 401 Bypass to the Share Endpoint Only#12905
danny-avila merged 1 commit into
devfrom
codex-fix-public-share-redirect

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Summary

Fixes #12890 by preventing unrelated unauthenticated API 401s from forcing public shared-link pages to redirect to login.

Public share pages intentionally load /api/share/:shareId without an access token, but other app-level queries can still run on the page. In the reported flow, /api/share/:id returned 200, then /api/mcp/servers returned 401, and the global Axios interceptor attempted refresh + redirected to /login?redirect_to=/share/:id.

This PR narrows the unauthenticated share-page exception to only GET /api/share/:shareId, including base-prefixed deployments such as /chat/api/share/:shareId. Other unauthenticated 401s on public share pages now reject normally instead of triggering login navigation.

Validation

  • git diff --cached --check
  • git diff --check

I attempted npx jest specs/request-interceptor.spec.ts --runInBand, but this worktree is missing the package dependency tree (jest-junit), so the focused spec could not run locally without reinstalling dependencies.

Copilot AI review requested due to automatic review settings May 1, 2026 11:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a client-side auth-interceptor edge case where public shared-link pages could be redirected to login due to unrelated unauthenticated 401s, by narrowing the “share page” exception to only the shared-messages data fetch endpoint.

Changes:

  • Adds share-page and shared-link-request detection helpers (including support for base-prefixed deployments) to constrain the 401 refresh/redirect flow.
  • Updates the 401 interceptor guard to only bypass the “no Authorization header” early-reject for GET /api/share/:shareId.
  • Extends request-interceptor unit tests to cover base-prefixed share URLs and to ensure unrelated 401s don’t cause login redirects on share pages.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/data-provider/src/request.ts Refines the Axios 401 interceptor guard by introducing share-page + shared-link request detection helpers.
packages/data-provider/specs/request-interceptor.spec.ts Adds/updates tests to validate the narrowed guard behavior on share pages and base-prefixed routes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/data-provider/src/request.ts Outdated
Comment on lines +78 to +95
const isSharePage = () =>
/(?:^|\/)share\/[^/]+\/?$/.test(stripBasePath(window.location.pathname));

const getRequestPathname = (url?: string) => {
if (typeof url !== 'string') {
return '';
}
try {
return new URL(url, window.location.origin).pathname;
} catch {
return url.split(/[?#]/)[0] ?? '';
}
};

const isSharedMessagesRequest = (url?: string, method?: string) =>
method?.toLowerCase() === 'get' &&
/(?:^|\/)api\/share\/[^/]+$/.test(getRequestPathname(url));

Comment on lines +117 to +158
it('recognizes base-prefixed shared link data requests', async () => {
expect.assertions(2);
setTokenHeader(undefined);

setWindowLocation({
href: 'http://localhost/chat/share/abc123',
pathname: '/chat/share/abc123',
search: '',
hash: '',
origin: 'http://localhost',
} as Partial<Location>);

mockAdapter.mockRejectedValueOnce({
response: { status: 401 },
config: { url: '/chat/api/share/abc123', method: 'get', headers: {} },
});

mockAdapter.mockResolvedValueOnce({
data: { token: 'new-token' },
status: 200,
headers: {},
config: {},
});

mockAdapter.mockResolvedValueOnce({
data: { sharedLink: {} },
status: 200,
headers: {},
config: {},
});

try {
await axios.get('/chat/api/share/abc123');
} catch {
// may reject depending on exact flow
}

expect(mockAdapter.mock.calls.length).toBe(3);

const refreshCall = mockAdapter.mock.calls[1];
expect(refreshCall[0].url).toContain('api/auth/refresh');
});
@danny-avila danny-avila changed the title [codex] Fix public share 401 redirect guard fix: public share 401 redirect guard May 1, 2026
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-12905 index is now live on the MCP server.
Deploy run

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ 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".

@danny-avila
danny-avila force-pushed the codex-fix-public-share-redirect branch from b80381d to 1207a6b Compare May 1, 2026 11:16
@danny-avila
danny-avila changed the base branch from main to dev May 1, 2026 11:16
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-12905 index is now live on the MCP server.
Deploy run

@danny-avila
danny-avila force-pushed the codex-fix-public-share-redirect branch from 1207a6b to 0a4b673 Compare June 20, 2026 14:53
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 0a4b673f80

ℹ️ 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".

@danny-avila
danny-avila marked this pull request as ready for review June 20, 2026 15:13
@danny-avila danny-avila changed the title fix: public share 401 redirect guard 🎯 fix: Narrow Public Share 401 Bypass to the Share Endpoint Only Jun 20, 2026
@danny-avila
danny-avila merged commit c9180d1 into dev Jun 20, 2026
31 checks passed
@danny-avila
danny-avila deleted the codex-fix-public-share-redirect branch June 20, 2026 17:57
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.

[Bug]: Shared link redirects to login page even if ALLOW_SHARED_LINKS_PUBLIC=true

2 participants