Skip to content

fix(token-vault): allow requests to resource server endpoints similar to AM endpoints - #598

Open
ancheetah wants to merge 1 commit into
developfrom
guard-am-requests
Open

ancheetah wants to merge 1 commit into
developfrom
guard-am-requests

Conversation

@ancheetah

Copy link
Copy Markdown
Contributor

JIRA Ticket

Description

Ensure that requests to AM for supported endpoints are only proxied when the request origin is an AM origin. Requests to the resource server with endpoints similar in name to supported AM endpoints should still be allowed with the access token sent only in the authorization header.

@changeset-bot

changeset-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c584ebc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@forgerock/token-vault Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the test label Oct 14, 2026
@nx-cloud

nx-cloud Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit c584ebc

Command Status Duration Result
nx affected -t build lint test docs e2e-ci ✅ Succeeded 32s View ↗
nx-cloud record -- nx format:check --verbose ✅ Succeeded 5s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-14 23:36:33 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/javascript-sdk@598
pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/ping-protect@598
pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/token-vault@598

commit: c584ebc

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 153 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.05%. Comparing base (87775ec) to head (c584ebc).
⚠️ Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
packages/token-vault/src/lib/proxy.ts 0.00% 153 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop     #598       +/-   ##
============================================
- Coverage    56.72%   27.05%   -29.67%     
============================================
  Files          105       11       -94     
  Lines        28457     1578    -26879     
  Branches      1644       49     -1595     
============================================
- Hits         16143      427    -15716     
+ Misses       12314     1151    -11163     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* flows, not the generic resource proxy
*/
if (requestOrigin === amOrigin) {
// If the request origin was an AM origin and no allowed AM endpoint was targeted then error

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.

Can we make this code comment like the others to draw attention to this?

/** ****************************************************
 * UNSUPPORTED AM ENDPOINT ERROR
 * If the request origin was an AM origin but endpoint
 * was unrecognized return error.
 */

Comment on lines +412 to +419
if (!tokens) {
const errorResponse = createErrorResponse(
'no_tokens',
new Error('No OAuth/OIDC tokens found'),
);
responseChannel.postMessage(errorResponse);
return;
}

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.

Can you share why you added this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Previously this check was done right before proxying allowed AM requests that needed a token. That token check is still done but is now wrapped up inside of the parent if (requestOrigin === amOrigin) conditional. So the check is no longer applied before making a fall-through proxied resource request. We need to do the same token check now when we reach this fallback because the request requires the token be sent in the auth header.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On closer inspection, this is needed to check both tokens.tokenExpiry and tokens.refreshToken downstream. It seems at this point we are still expecting tokens to exist so I think this is valid but lmk otherwise.

@ryanbas21 ryanbas21 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.

I don't have anything to add Justin commented on the one block i was looking at as well

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants