DataFed icon indicating copy to clipboard operation
DataFed copied to clipboard

[DAPS-1754] - bug web oauth state parameter

Open JoshuaSBrown opened this issue 2 months ago • 1 comments

Ticket

Description

How Has This Been Tested?

Artifacts (if appropriate):

Tasks

  • [ ] - A description of the PR has been provided, and a diagram included if it is a new feature.
  • [ ] - Formatter has been run
  • [ ] - CHANGELOG comment has been added
  • [ ] - Labels have been assigned to the pr
  • [ ] - A reviwer has been added
  • [ ] - A user has been assigned to work on the pr
  • [ ] - If new feature a unit test has been added

Summary by Sourcery

Generate a cryptographically secure random state parameter for OAuth consent URLs and update tests to validate its format.

Bug Fixes:

  • Replace hardcoded default state parameter in getGlobusConsentURL with a dynamic random value to address security concerns

Enhancements:

  • Introduce generateState helper that uses window.crypto.getRandomValues to produce a 16-byte hex string for OAuth state

Tests:

  • Update getGlobusConsentURL tests to assert that the generated state is a 32-character hexadecimal string

JoshuaSBrown avatar Nov 06 '25 21:11 JoshuaSBrown

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR replaces the hardcoded OAuth state parameter with a cryptographically secure, randomly generated hex string and updates the unit tests to verify the new behavior.

Sequence diagram for OAuth consent URL generation with random state parameter

sequenceDiagram
participant Client
participant "api.js"
participant "window.crypto"
Client->>"api.js": getGlobusConsentURL(...)
"api.js"->>"window.crypto": generateState()
"window.crypto"-->>"api.js": random hex string
"api.js"->>Client: Calls _asyncGet with state=random hex string

Class diagram for updated getGlobusConsentURL and generateState functions

classDiagram
class api {
  +getGlobusConsentURL(a_cb, collection_id, requested_scopes, refresh_tokens, query_params, state)
  +themeSave(a_theme, a_cb)
  +generateState()
}
api : getGlobusConsentURL() uses generateState() for state parameter
api : generateState() returns random hex string

File-Level Changes

Change Details Files
Introduce secure random state generation for OAuth flows
  • Added generateState() util using window.crypto to produce a 16-byte hex string
  • Updated getGlobusConsentURL default state parameter to call generateState() instead of using a fixed value
web/static/api.js
Update tests to validate generated state format
  • Removed hardcoded state assertion
  • Added assertions ensuring state is a string of 32 lowercase hex characters
web/test/api.test.js

Possibly linked issues

  • #1754: The PR changes the oauth state parameter from '_default' to a randomized value by implementing a generateState function in getGlobusConsentURL.
  • #1754: PR adds generateState to Globus consent URL for secure state parameter, directly fixing the issue's security vulnerability.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Nov 06 '25 21:11 sourcery-ai[bot]