Skip to content

Conversation

@JoshuaSBrown
Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown commented Nov 6, 2025

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

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 6, 2025

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
Loading

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
Loading

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


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

@JoshuaSBrown JoshuaSBrown requested a review from nedvedba November 6, 2025 21:41
@JoshuaSBrown JoshuaSBrown self-assigned this Nov 6, 2025
@JoshuaSBrown JoshuaSBrown added Type: Bug Something isn't working Priority: Medium Above average priority labels Nov 6, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • You should persist the generated state value (e.g. in sessionStorage or a closure) so you can verify it against the state returned in the OAuth callback for proper CSRF protection.
  • Consider enhancing the test to call generateState multiple times and assert the outputs are unique to catch any randomness issues rather than only checking format.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- You should persist the generated state value (e.g. in sessionStorage or a closure) so you can verify it against the state returned in the OAuth callback for proper CSRF protection.
- Consider enhancing the test to call generateState multiple times and assert the outputs are unique to catch any randomness issues rather than only checking format.

## Individual Comments

### Comment 1
<location> `web/test/api.test.js:71` </location>
<code_context>
+
+            // Check that state exists and matches the format generated by generateState
+            expect(options.data.state).to.be.a("string");
+            expect(options.data.state).to.match(/^[0-9a-f]{32}$/); // 16 bytes -> 32 hex chars
+	   
             options.success({ consent_url: "http://example.com" });
</code_context>

<issue_to_address>
**suggestion (testing):** Suggest adding a test for explicitly passing a custom state value.

Please add a test to verify that getGlobusConsentURL correctly uses a custom state value when one is provided.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


// Check that state exists and matches the format generated by generateState
expect(options.data.state).to.be.a("string");
expect(options.data.state).to.match(/^[0-9a-f]{32}$/); // 16 bytes -> 32 hex chars
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Suggest adding a test for explicitly passing a custom state value.

Please add a test to verify that getGlobusConsentURL correctly uses a custom state value when one is provided.

@JoshuaSBrown JoshuaSBrown changed the title 1754 bug web oauth state parameter [DAPS-1754] - bug web oauth state parameter Nov 18, 2025
@JoshuaSBrown JoshuaSBrown force-pushed the 1754-bug-web-oauth-state-parameter branch from c366e8f to 52ae762 Compare December 2, 2025 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Medium Above average priority Type: Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug, Security] - web, oauth state parameter is not set correctly.

3 participants