Closed Bug 1882344 Opened 2 years ago Closed 1 year ago

Website can obtain a wake lock that won't be released

Categories

(Core :: DOM: Core & HTML, defect)

defect

Tracking

()

RESOLVED FIXED
126 Branch
Tracking Status
firefox126 + fixed

People

(Reporter: vhilla, Assigned: vhilla)

References

(Blocks 1 open bug)

Details

(Keywords: csectype-dos, reporter-external, sec-low, Whiteboard: [adv-main126-])

Attachments

(1 file)

I'm not sure if this is a legitimate security issue, but Bug 1881070 shows a way for websites to obtain a screen wake lock that will not be released until the window closes. A website can prevent a device from turning off the screen or going to sleep even if it is not visible or active.

Example

window.addEventListener('load', async () => {
    iframe = document.createElement('iframe')
    document.documentElement.appendChild(iframe)
    lock = iframe.contentWindow.navigator.wakeLock.request()
}

Explanation

What's happening is that

  • iframe loads the initial about:blank, document A
  • invoking navigator.wakeLock creates a WakeLockJS object that is associated with the inner window and attaches activity, visibility listeners to document A
  • WakeLockJS::Request schedules WakeLockJS::Obtain in a runnable for obtaining a lock
  • iframe loads the target document B and due to this special case, the document is replaced while the inner window stays the same
  • WakeLockJS gets notified of document A changing activity. But it doesn't get notified of the document being changed, so does not update the listeners
  • Obtain creates a lock for document B
  • If document B becomes inactive or hidden, the lock won't be released as WakeLockJS won't be notified.

WakeLockJS needs to either be notified of the document being replaced, or the document has to UnlockAllWakeLocks on becoming inactive or hidden.

Note that this also happens if we create the WakeLockJS object immediately, but request a lock later. Still, to follow the spec, Obtain should create a lock for the document at the time Request was called.

Assignee: nobody → vhilla
Status: NEW → ASSIGNED
Group: core-security → dom-core-security

I appreciate the caution, but I think this doesn't really need to be a security issue. More of an annoyance than anything. I assume a user can still manually lock the screen or put the device to sleep.

Blocks: eviltraps
Group: dom-core-security
Severity: -- → S3
Duplicate of this bug: 1881070

Comment on attachment 9387880 [details]
Bug 1882344 - Have Document instead of WakeLockJS release locks on loss of activity. r=edgar,#dom-core

Beta/Release Uplift Approval Request

  • User impact if declined: We are concerned that some wake locks might fail to be released. This would cause user devices to not turn off the display automatically.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Not risky, as we merely stop the API in early beta from riding the train to release
  • String changes made/needed:
  • Is Android affected?: Yes
Attachment #9387880 - Flags: approval-mozilla-beta?

:vhilla is this patch dependent uplifting the disabling Screen Wake Lock API on late beta/release in bug 1883724?

Flags: needinfo?(vhilla)

Comment on attachment 9387880 [details]
Bug 1882344 - Have Document instead of WakeLockJS release locks on loss of activity. r=edgar,#dom-core

Oh, I'm sorry I wanted to request uplift for Bug 1883724

Flags: needinfo?(vhilla)
Attachment #9387880 - Flags: approval-mozilla-beta?
Blocks: 1874849
Pushed by vhilla@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a293e6927cab Have Document instead of WakeLockJS release locks on loss of activity. r=edgar,dom-core
Flags: needinfo?(vhilla)
Pushed by vhilla@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8130451713b9 Have Document instead of WakeLockJS release locks on loss of activity. r=edgar,dom-core
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 126 Branch
Flags: needinfo?(vhilla)
Whiteboard: [adv-main126-]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: