Skip to content

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

Merged
ancheetah merged 1 commit into
developfrom
guard-am-requests
Oct 21, 2026
Merged

ancheetah merged 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: de96cf6

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 de96cf6

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

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


☁️ Nx Cloud last updated this comment at 2026-10-21 21:40:07 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/token-vault@598
pnpm add https://pkg.pr.new/ForgeRock/forgerock-javascript-sdk/@forgerock/ping-protect@598

commit: de96cf6

@codecov-commenter

codecov-commenter commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 157 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.99%. Comparing base (174be55) to head (de96cf6).

Files with missing lines Patch % Lines
packages/token-vault/src/lib/proxy.ts 0.00% 157 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop     #598       +/-   ##
============================================
- Coverage    56.58%   26.99%   -29.60%     
============================================
  Files          105       11       -94     
  Lines        28534     1582    -26952     
  Branches      1644       49     -1595     
============================================
- Hits         16145      427    -15718     
+ Misses       12389     1155    -11234     

☔ 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.

Comment thread packages/token-vault/src/lib/proxy.ts Outdated
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

@ancheetah
ancheetah force-pushed the guard-am-requests branch 2 times, most recently from 878f18b to 64312db Compare October 20, 2026 20:46
@ancheetah
ancheetah merged commit f5caafe into develop Oct 21, 2026
8 checks passed
@ancheetah
ancheetah deleted the guard-am-requests branch October 21, 2026 22:14
@ryanbas21 ryanbas21 mentioned this pull request Oct 21, 2026

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

Looks great!

Good to have a check for non-AM URLs to they are not tangled by our endpoints!

And the !tokens check makes sense too outside the if (requestOrigin === amOrigin) check!

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.

5 participants