Bug 182972 - WebCrypto keys break autoincrementing primary keys of IndexedDB
Summary: WebCrypto keys break autoincrementing primary keys of IndexedDB
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: https://gist.github.com/sechel/415c34...
Keywords: InRadar
Depends on:
Blocks: 133122 160306
  Show dependency treegraph
 
Reported: 2018-02-20 07:16 PST by Stefan Sechelmann
Modified: 2019-10-25 03:21 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Sechelmann 2018-02-20 07:16:08 PST
When storing an object that contains a WebCrypto CryptoKey to an IDB object store with auto incrementing primary key we get the following error:
Error: Unable to inject record key into record value

See also https://gist.github.com/sechel/415c34b9bf80f3adeba52856d2377393
Comment 1 Jiewen Tan 2018-02-20 11:53:42 PST
I tried the test case in Safari. It doesn't reproduce the bug. A very primitive suggestion here is to see if SerializedCryptoKeyWrap.h has caused some troubles for GTK+.
Comment 2 Jiewen Tan 2018-02-20 12:00:42 PST
I remember I told Zan not to wrap/unwrap Crypto Keys for GTK+, so it shouldn't cause any troubles for you.

Wrapping crypto keys when storing them into IndexedDB is a legacy behavior to protect them in order to address early limitations of the spec. However, since we have existing clients that have already stored wrapped keys in IndexedDb, Apple ports couldn't get rid of it at this moment.
Comment 3 Zan Dobersek 2018-02-20 13:07:04 PST
(In reply to Jiewen Tan from comment #2)
> I remember I told Zan not to wrap/unwrap Crypto Keys for GTK+, so it
> shouldn't cause any troubles for you.
> 
> Wrapping crypto keys when storing them into IndexedDB is a legacy behavior
> to protect them in order to address early limitations of the spec. However,
> since we have existing clients that have already stored wrapped keys in
> IndexedDb, Apple ports couldn't get rid of it at this moment.

Keys are still not wrapped for the GTK+ port, as recommended.

At least per this bug report, issue is observed with the Safari Tech Preview. OTOH the test case passes on GTK+/WPE as well, meaning that the issue appears to be present (as otherwise the test case would fail).
Comment 4 Zan Dobersek 2018-02-20 13:33:13 PST
Failure occurs during deserialization because UniqueIDBDatabase provides an ExecState from which a usable ScriptExecutionContext cannot be retrieved. That's currently necessary in order to pipe the serialization and deserialization operations all the way up to the WebChromeClient in UIProcess.

https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/bindings/js/SerializedScriptValue.cpp#L477
https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/bindings/js/ScriptState.cpp#L65
Comment 5 Stefan Sechelmann 2018-02-20 14:02:57 PST
> OTOH the test case passes on GTK+/WPE as well, meaning that the issue appears to be present (as otherwise the test case would fail).
Thats right, sorry for causing confusion. The test case is written canary style meaning it will fail if the issue has been resolved.

BTW, this bug seems to be related as it also involves creating indices with WebCrypto keys present:
https://bugs.webkit.org/show_bug.cgi?id=177350
Comment 6 Stefan Sechelmann 2018-09-14 05:24:28 PDT
Anything new in the meantime? I will now perform another attempt to port out web application to Safari. Its pretty frustrating that I need so many Workarounds just due to WebCrypto.
Comment 7 Stefan Sechelmann 2019-10-25 03:20:35 PDT
This has been fixed in Safari 13.x.x.
Comment 8 Radar WebKit Bug Importer 2019-10-25 03:21:16 PDT
<rdar://problem/56613473>