<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>183167</bug_id>
          
          <creation_ts>2018-02-27 11:52:14 -0800</creation_ts>
          <short_desc>Cannot store CryptoKey to IndexedDB in ServiceWorker</short_desc>
          <delta_ts>2024-03-15 13:42:38 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Service Workers</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=174541</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=177350</see_also>
          <bug_file_loc>https://embed.plnkr.co/9BWkuIAmxX2EITOWI2yR/</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Stefan Sechelmann">stefan</reporter>
          <assigned_to name="Nitin Mahendru">nitinmahendru</assigned_to>
          <cc>beidson</cc>
    
    <cc>bfulgham</cc>
    
    <cc>cdumez</cc>
    
    <cc>jdknezek+webkit-bugzilla</cc>
    
    <cc>jiewen_tan</cc>
    
    <cc>joliccin</cc>
    
    <cc>katherine_cheney</cc>
    
    <cc>sihui_liu</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1402373</commentid>
    <comment_count>0</comment_count>
    <who name="Stefan Sechelmann">stefan</who>
    <bug_when>2018-02-27 11:52:14 -0800</bug_when>
    <thetext>Attempting to store a WebCrypto CryptoKey in an object store of IndexedDB results in a DataCloneError: &quot;Failed to store record in an IDBObjectStore: An object could not be cloned.&quot; See this test case for a demonstration: https://embed.plnkr.co/9BWkuIAmxX2EITOWI2yR/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1402921</commentid>
    <comment_count>1</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-03-01 09:32:20 -0800</bug_when>
    <thetext>Sounds like we do not support cloning / serializing CryptoKey objects. Likely not truly an IDB issue. Jiewen should probably take a look.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1402922</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-03-01 09:33:15 -0800</bug_when>
    <thetext>In particular, I suspect we did not implement this part of the spec:
https://www.w3.org/TR/WebCryptoAPI/#cryptokey-interface-clone</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1402923</commentid>
    <comment_count>3</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2018-03-01 09:43:19 -0800</bug_when>
    <thetext>The test URL does not seem to work for me. I see it installing a service worker (not sure what this bug has to do with service workers). If I inspect the service worker, I see there is code using IndexedDB but it is not executed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1402937</commentid>
    <comment_count>4</comment_count>
    <who name="Jiewen Tan">jiewen_tan</who>
    <bug_when>2018-03-01 10:42:10 -0800</bug_when>
    <thetext>We do support storing CryptoKey into IndexedDB. However, due to some legacy reasons, we wrap the objects before storing them into IndexedDB. Here is file: See SerializedCryptoKeyWrap.h. For any new implementations, I recommend we don&apos;t wrap CryptoKeys anymore. Since the wrapping APIs will be called in SerializedScriptValue.h, failing to implement those would fail IndexedDB interactions. An example to circumvent that is to implement dummy APIs, see SerializedCryptoKeyWrapGCrypt.cpp.

I am not sure if ServiceWorker needs to implement this dummy APIs though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1402979</commentid>
    <comment_count>5</comment_count>
    <who name="Stefan Sechelmann">stefan</who>
    <bug_when>2018-03-01 12:03:10 -0800</bug_when>
    <thetext>The error occurs in service workers only. The example stores a set of objects including a WebCrypto key upon fetch. Please edit the source in the test to trigger the fetch. (and the error)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1452824</commentid>
    <comment_count>6</comment_count>
    <who name="Joseph Liccini">joliccin</who>
    <bug_when>2018-08-22 15:04:45 -0700</bug_when>
    <thetext>I also am running into this issue.

It is not specific to IndexedDB as noted.

It occurs with postMessage as well, so it is indeed related to the structured clone algorithm from within the Service Worker Global Scope context.

I am able to use the structured clone algorithm for CryptoKeys within the Window context, but not within the ServiceWorkerGlobalScope context.

You can get the same exception by trying to `postMessage` to a `Client` object from the service worker the `CryptoKey`.  And you will get the same &apos;DataClone&apos; error.

But a `postMessage` on the `window` object via `window.navigator.serviceWorker.controller.postMessage` will not throw the exception.  In this case the structured clone succeeds.

I can prepare a Plunkr soon.

I am hypothesizing that a workaround would be for the service worker to only perform `read` operations into IndexedDB for the CryptoKey, and all write operations will have to happen on the Main thread.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1453137</commentid>
    <comment_count>7</comment_count>
    <who name="Joseph Liccini">joliccin</who>
    <bug_when>2018-08-23 11:22:27 -0700</bug_when>
    <thetext>Here is a Plunk with a Repro: https://embed.plnkr.co/s2I0U0/

Is it possible that SerializedScriptValue.h for CryptoKey objects runs a different implementation when in the main thread vs. Service Worker thread context?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1836084</commentid>
    <comment_count>8</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-02-01 11:27:10 -0800</bug_when>
    <thetext>&lt;rdar://problem/88339459&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2008663</commentid>
    <comment_count>9</comment_count>
    <who name="Jonathan Knezek">jdknezek+webkit-bugzilla</who>
    <bug_when>2024-01-29 14:42:13 -0800</bug_when>
    <thetext>We are encountering this bug when trying to postMessage a CryptoKey between a window and service worker. A gist with a simple reproduction is available here: https://gist.github.com/jknezek-locktera/f355371af152b4469772ded0f20de314

Has there been any movement on this since... 2018?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2017949</commentid>
    <comment_count>10</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2024-03-01 02:12:52 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/25342</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2020996</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-03-14 06:27:49 -0700</bug_when>
    <thetext>Committed 276088@main (51ae1a6d501e): &lt;https://commits.webkit.org/276088@main&gt;

Reviewed commits have been landed. Closing PR #25342 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2021062</commentid>
    <comment_count>12</comment_count>
    <who name="Nitin Mahendru">nitinmahendru</who>
    <bug_when>2024-03-14 11:01:33 -0700</bug_when>
    <thetext>Re-opening for pull request https://github.com/WebKit/WebKit/pull/25871</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2021440</commentid>
    <comment_count>13</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-03-15 13:42:36 -0700</bug_when>
    <thetext>Committed 276197@main (fdb77ba046f0): &lt;https://commits.webkit.org/276197@main&gt;

Reviewed commits have been landed. Closing PR #25871 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>