Closed Bug 2034083 Opened 6 months ago Closed 6 months ago

Permission prompts replaced by a new prompt with the same ID leave the original request dangling

Categories

(Firefox :: Site Permissions, defect, P2)

defect

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox152 --- fixed

People

(Reporter: emz, Assigned: emz)

References

()

Details

(Keywords: ai-involved)

Attachments

(4 external files)

When PermissionUI.sys.mjs's PermissionPrompt.prompt() is called a second time for the same permission on the same browser — e.g. a page calling navigator.geolocation.getCurrentPosition() twice in quick succession — PopupNotifications.show() silently replaces the existing popup. The old notification's eventCallback fires "removed" but without the isCancel flag, so PermissionUI's if (isCancel) this.cancel() gate skips the cancel and the underlying nsIContentPermissionRequest is never answered. The content-side promise dangles forever.

The same dangling pattern affects tab close, navigation away, and docshell swap paths inside PopupNotifications.sys.mjs — those also fire "removed" without passing the flag. WebRTC prompts (WebRTCParent.sys.mjs) have the same gate and leak in the same situations.

Steps to reproduce:

  1. Load a page that calls navigator.geolocation.getCurrentPosition(ok, err) twice synchronously. For example https://playground.emz.run/repeated-permission-request/
  2. Observe two prompts are requested; the first is immediately replaced.
  3. The first call's ok/err callbacks are never invoked.

Expected: the first request receives PERMISSION_DENIED so the content-side promise settles.

Eventually we might want to do a chaining approach like suggested in Bug 2033443 to resolve this, but for now we should cancel old requests that no longer have an associated notification (prompt) for consistency. This also means websites know that their request got rejected rather than leaving them hanging indefinitely.

Actual: the first request dangles indefinitely.

Keywords: ai-involved

PopupNotifications fires "removed" from several external-removal paths
(tab close, navigation, same-id replacement, refused docshell swap,
removeOnDismissal) without setting the flag that signals "no user
response," leaving permission prompts' underlying
nsIContentPermissionRequest dangling. Pass withoutUserResponse=true on
those paths; action-callback paths keep the default false because
allow()/cancel() already ran.

The flag is also renamed from isCancel (permission-subsystem vocabulary)
to withoutUserResponse, describing the signal from PopupNotifications'
own POV. PermissionUI, WebRTCParent, and the external callers that pass
the flag explicitly are updated to match.

Assignee: nobody → emz
Status: NEW → ASSIGNED

ShowPrompt already calls nsContentPermissionUtils::AskPermission in its
Pending branch, but Start then fell through to call AskPermission a
second time. A single persist() pushed two notifications with the same
id through PopupNotifications for the same underlying request.

The duplicate used to be silently absorbed by PopupNotifications.show's
same-id replacement. After the PopupNotifications.sys.mjs refactor
earlier in this stack, that replacement now fires "removed" with
withoutUserResponse=true, which PermissionUI treats as a signal to
cancel the request. Since both notifications shared the same request,
cancel() resolved the persist() promise before the user's Allow click
could run, breaking browser_permissionsPromptAllow.js.

Check permission delegation directly and call AskPermission once.
CheckPermissionDelegate preserves the delegation guard that used to
live inside ShowPrompt. The Android workaround branch is no longer
needed because both platforms now take the single-ask path.

Pushed by ezuehlcke@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/95aa38468382 https://hg.mozilla.org/integration/autoland/rev/1cfd12d2eb32 Cancel unanswered permission prompts on every PopupNotifications removal path, and rename isCancel to withoutUserResponse. r=Gijs,sfoster https://github.com/mozilla-firefox/firefox/commit/8d99475596f8 https://hg.mozilla.org/integration/autoland/rev/041ffb13c6bb Add browser mochitest for replaced geolocation prompts cancelling the first request. r=Gijs https://github.com/mozilla-firefox/firefox/commit/9a114c5b96dc https://hg.mozilla.org/integration/autoland/rev/b1aea331ad76 Add browser mochitest for refused-swap PopupNotifications removal firing withoutUserResponse. r=Gijs https://github.com/mozilla-firefox/firefox/commit/70c40a9442e6 https://hg.mozilla.org/integration/autoland/rev/823adb8a187f Avoid double AskPermission in PersistentStoragePermissionRequest::Start. r=dom-storage-reviewers,hsingh
Regressions: 2034975
No longer regressions: 2034975
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: