Skip to content

fix: prevent app token from being generated more than once - #3541

Merged
JammingBen merged 8 commits into
opencloud-eu:mainfrom
eriktews:debounce
Oct 6, 2026
Merged

JammingBen merged 8 commits into
opencloud-eu:mainfrom
eriktews:debounce

Conversation

@eriktews

@eriktews eriktews commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Description

When a user clicks the confirm button when generating a new app token more than once in quick succession, then the app token is generated more than once in the backend, but only one secret might be visible to the user.

There is a similar issue as well when generating invite tokens and this is fixed here as well.

Also, when a the app token generation fails in the backend, then this error would not be shown to the user. It's also fixed here.

It could be possible to generate screenshots for the change, but it's a bit difficult since everything happens rather fast.

Related Issue

None

How Has This Been Tested?

The app token code was tested with this pr being applied to the 8.0.1 version. The error display and the remaining changes were only tested in unit tests.

I would encourage testing this carefully in a review.

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

Creating an app token is not idempotent: every request to POST
/auth-app/tokens mints a new one. The confirm button was only disabled
based on form validity, so it stayed enabled for the whole round-trip
and a second click sent a second request. Only the last response was
ever displayed, leaving the first token alive on the server with its
secret never shown to the user.

Track an in-flight `isCreating` ref, fold it into the existing
`isConfirmDisabled` guard and reset it in a `finally` block. The ref is
set before awaiting, so the guard also covers clicks that land before
the re-render disables the button - disabling alone would leave a
window open. The button shows a spinner while the request is in flight,
matching InviteCollaboratorForm and OcModal.
createAppToken swallowed failures into console.error, leaving the form
untouched with no explanation - the modal looked like the click simply
had no effect, and the user had no way to tell a rejected request from a
missed one.

Show an error message on failure, matching how AppTokens already reports
deletion errors, and keep the form usable so the request can be retried.
The ScienceMesh invite flow had the same double-request bug as the app
token modal: generateToken was reachable both from the modal confirm
button and from the inner form's submit handler, neither of which was
guarded while a request was in flight. Generating an invite token mints
a new one per request, so a double click or a click plus an Enter press
produced two tokens.

Track an in-flight ref, fold it into the existing validation guard and
reset it in the finally block, then bind it to the modal so the confirm
button is disabled and shows a spinner while generating. OcModal delays
its spinner, so short requests do not flash.

Adds the package's first unit tests, which requires declaring
web-test-helpers as a dev dependency.
…eated

The create modal is dispatched with hidden actions, so the only ways out
are the confirm button and the modal's cancel button. The confirm button
was guarded against repeated clicks, but the cancel button was not: it
is disabled via the modal's isLoading flag, which nothing set while
creating a token, and OcModal cancels on Escape regardless of isLoading.

Cancelling mid-request unmounts the component, the request still
completes, and the resulting token is never displayed - the same orphaned
credential the click guard was meant to prevent, reachable with a single
keypress. Pressing Escape was arguably the likeliest way to hit it.

Mark the modal as loading around the request, which disables the cancel
button, and block Escape in OcModal while loading to match the button it
sits next to. updateModal now bails out when the modal has already been
removed, since an async handler can outlive its modal.

@JammingBen JammingBen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, looks mostly good, only a few nitpicks from my side.

@eriktews

eriktews commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@JammingBen I took all your feedback into account, please review the current state again.

@JammingBen JammingBen changed the title Prevent new app token from being generated more than one fix: prevent app token from being generated more than once Oct 6, 2026
@JammingBen
JammingBen merged commit d4eebe3 into opencloud-eu:main Oct 6, 2026
32 checks passed
@openclouders openclouders mentioned this pull request Oct 6, 2026
1 task
openclouders pushed a commit that referenced this pull request Oct 6, 2026
fix: prevent app token from being generated more than once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants