Skip to content

fix: API requests utilize single auth mechanism - #166

Merged
dcalhoun merged 6 commits into
trunkfrom
fix/api-requests-utilize-single-auth-mechanism
Aug 19, 2025
Merged

dcalhoun merged 6 commits into
trunkfrom
fix/api-requests-utilize-single-auth-mechanism

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Aug 15, 2025 •

Copy link
Copy Markdown
Member

What?

Omit credentials (cookies) for apiFetch calls.

Why?

Fix CMM-684.

GutenbergKit is setup to utilize token authentication. The presence of
authentication cookies means there were duplicative authentication mechanisms,
which can cause failed requests for some endpoints that favor cookies.

How?

  • Set credentials: 'omit' for all apiFetch calls.
  • Add automated tests, including refactoring to avoid stale closure variables in
    tests.
  • Modify Vitest configuration to default to the jsdom environment—the most
    common for this project.
  • Update caniuse database to avoid out-of-date logs in npm commands.

Testing Instructions

See wordpress-mobile/WordPress-iOS#24747.

Accessibility Testing Instructions

N/A, no user-facing changes.

Screenshots or screencast

N/A, no user-facing changes.

GutenbergKit is intended to authentication REST API requests via
authentication tokens. If WordPress authentication cookies are present
in the request, it will take precedent over the authentication token
present in the request. This can result in request authentication
failures.
Simplify test set up by defaulting to the most common environment for
this project.
@dcalhoun dcalhoun added the [Type] Bug An existing feature does not function as intended label Aug 15, 2025
Avoid out-of-date warnings logged in `npm` commands.
Comment thread src/utils/api-fetch.js
}
if ( authHeader ) {
options.headers.Authorization = authHeader;
options.credentials = 'omit'; // Avoid cookies disrupting token authentication

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the primary change to address the bug.

@dcalhoun
dcalhoun requested a review from Copilot August 18, 2025 13:10

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

This PR fixes authentication conflicts in API requests by ensuring token-based authentication uses a single mechanism instead of competing with cookies. When an auth header is present, credentials are set to 'omit' to prevent browser cookies from interfering with token authentication.

  • Refactored API fetch middleware to dynamically handle token authentication and omit credentials
  • Added comprehensive test coverage for the new credentials handling behavior
  • Updated Vitest configuration to default to jsdom environment for better test consistency

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/utils/api-fetch.js Refactored authentication middleware to dynamically set credentials to 'omit' when using token auth
src/utils/api-fetch.test.js Added comprehensive test suite covering various credential handling scenarios
vitest.config.js Set default test environment to jsdom for consistency across the project
src/components/editor/test/use-media-upload.test.jsx Removed redundant jsdom environment directive
src/components/editor-load-notice.test.jsx Removed redundant jsdom environment directive

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/utils/api-fetch.js
@dcalhoun
dcalhoun requested a review from crazytonyli August 18, 2025 13:20
@dcalhoun
dcalhoun merged commit 30ebac2 into trunk Aug 19, 2025
@dcalhoun
dcalhoun deleted the fix/api-requests-utilize-single-auth-mechanism branch August 19, 2025 11:01
jkmassel added a commit that referenced this pull request Aug 12, 2026
…ories

Resolves 29 Dependabot advisories in the dev dependency tree. None of
these packages ship in the iOS/Android app bundle -- they are build,
lint, and local-WP (`@wordpress/env`) tooling.

In-range bumps:
- `vite` 8.0.5 -> 8.2.1 (direct devDep; floor raised to `^8.0.16`) #134 #135
- `shell-quote` -> 1.10.0 (critical #133) #165
- `fast-uri` -> 3.1.5 #163 #164 #179 #206 #207
- `js-yaml` -> 3.15.1 / 4.3.1 #157 #158 #167 #168 #200 #201
- `brace-expansion` #160 #166, `immutable` #161 #162, `tmp` #131,
  `fast-xml-builder` #122 #123, `simple-git` #119,
  `@babel/plugin-transform-modules-systemjs` #126

Scoped `overrides` (parents exact-pinned the vulnerable version):
- `ws` -> 8.21.0, keeping 7.5.13 for `react-devtools-core` #138 #153
- `qs` -> 6.15.2 under `@wordpress/env` #130
- `minimatch` -> 9.0.9 under `@typescript-eslint/typescript-estree` #65
- `@babel/core` -> 7.29.7 under `@wordpress/babel-preset-default` #154

Not addressed here: `electron` (33 alerts) and its bundled `got` (#33)
are pinned by `react-devtools@7.0.1` -- already the latest, and npm's
only "fix" is a breaking downgrade to `react-devtools@1.0.5`.
Runtime-scope advisories (`seroval`, `nanoid`, `postcss`, `showdown`,
`uuid`) are out of scope for a dev-only bump.

Verified: `npm run test:unit` (202 passing) and `npm run build` green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants