WebCrypto API badly documented

  1. It’s hard to understand, sometimes and misses information about intended usage/constraints/limitations/suggestions. E.g. the wrapKey method. It’s as it is intended in “unsecure environments”. So, what? It does not even mention taht it basically just encrypts the key, it does not mention whether and why you should/could not just use the encrypt() API (or could you?), and so on and so forth…
    The documentation is really minimal and that may easily lead to security problems.

  2. It does not give any recommendations or warnings., It does not warn about problematic constructions/cipher modes. It does not state what values should be random etc. and so on… It’s just gives you the tools and you can shoot yourself in the foot.

  3. But worst, it gives actually bad examples. E.g. the deriveKey one: It uses PBKDF2-SHA256 with 100 iterations! Seriously just 100 ones – you can literally just skip that key stretching. That’s just way too less.
    It even adds a great and totally (not) useful comment there:

    don’t get too ambitious, or at least remember that low-power phones will access your app

    Seriously that’s bad advice.
    Similarly, it often uses CBC mode or something like that instead of the usually recommend ones like GCM

IMHO this state is not acceptable and quite low-quality. The doc often advises not use "
naïve approaches for converting text" and such helps to avoid such relatively harmless problems, but at the same time when it comes to cryptography pitfalls, it actually even suggests to fall into them… :disappointed_relieved:

3 Likes

I’d suggest fixing the easiest issues, and reporting the problems, that you have no time to fix yourself.

By the way, you can make bug reports in Bugzilla from MDN articles directly from the menu (see screenshot). I hope this is new information for somebody.

1 Like

I’ve filed https://bugzilla.mozilla.org/show_bug.cgi?id=1488456 for this. Thanks for reporting it @rugkx.

2 Likes

A follow-up on this, because many things have happened and I really appreciate the work MDN/@wbamberg put into this. They’ve identified more problems and many pages are now ready for review! :tada:

It’s great to see, how ones feedback can impact the MDN doc and – to speak of the greater meaning – the state of the web (as documentation is vital to the web, especially crypto, which devs can easily get wrong without a good doc) in such a positive way. :+1:

3 Likes