# Upgrade agent-js to resolve a Chrome issue

**URL:** <https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364>\
**Category:** Developers\
**Created:** [August 24, 2023, 4:53pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364 "2023-08-24T16:53:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfx-json](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/dfx-json/32/4784_2.png) [@dfx-json](https://forum.dfinity.org/u/dfx-json)\
**Post date:** [August 24, 2023, 4:53pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/1 "2023-08-24T16:53:10Z")

</div>

TLDR: upgrade to [agent-js 0.19.2](https://github.com/dfinity/agent-js) and redeploy your canisters to resolve an issue that has been affecting some IC dapps when using some versions of Chrome.

# Issue

Some users were receiving a 502 response when attempting to access a canister through their Chrome browsers. This was due to an invalid signature verification from a `read_state` call.

# Problem

A particular version of Chrome (we tested against `Version 115.0.5790.102 `) is somehow incorrectly executing the [JS SHA-256 implementation used to create request IDs](https://github.com/dfinity/agent-js/blob/67b1e38e7d234e03a859f77da6fe40571408815a/packages/agent/src/request_id.ts#L13-L15JS). Our best guess is that it is JIT related because the values are correct for a while.

Once the SHA-256 implementation ends up in a bad state it seems at least **consistently** wrong - all of the outputs are incorrect, and repeated calls for the same input produce the same incorrect hash. So in principle this could be detected at runtime by hashing some fixed string and comparing it against the known good output.

# Solution

We have changed the hashing library that agent-js uses to generate SHA-256 hashes to the [@noble/hashes](https://github.com/paulmillr/noble-hashes) library as a stop-gap solution.

Moving forward, we will migrate to native `WebCrypto` and `node crypto`, but this will take time since they would transform all of our hash calls into promises and require significant refactoring.

A new agent-js version has been released with a different hashing library. Please update your projects and redeploy so that any users using an affected version of Chrome do not experience down time.

Many thanks.

EDIT

If you are also experiencing issues with the content security policy not recognizing the [icp-api.io](http://icp-api.io) domain (something along the lines of `Refused to connect to https://icp-api.io/api/v2/canister/xxxx because it violates the following Content Security Policy directive...` you can either:

1. edit your `ic-assets.json` file manually to include the icp-api domain in the CSP. It should look like this

```auto
"Content-Security-Policy": "default-src 'self';script-src 'self' 'unsafe-eval';connect-src 'self' https://icp0.io https://*.icp0.io https://icp-api.io;img-src 'self' data:;style-src * 'unsafe-inline';style-src-elem * 'unsafe-inline';font-src *;object-src 'none';base-uri 'self';frame-ancestors 'none';form-action 'self';upgrade-insecure-requests;"

```

1. install dfx version 0.14.4 (will be released week of Aug 28) and redeploy your canister. the icp-api domain will be added to the CSP by default.

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [August 24, 2023, 10:54pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/2 "2023-08-24T22:54:24Z")

</div>

This is all accurate, with the caveat that the refactor to WebCrypto may not be worth it since we still need the `@noble/hashes` library for sha224 hashes in `Principal` encoding and decoding, and switching to `Promise` based hashing would be a breaking change for a substantial number of API’s

---

<div class="post-metadata">

**Author:** ![Mitch](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mitch/32/4826_2.png) [@Mitch](https://forum.dfinity.org/u/Mitch)\
**Post date:** [September 1, 2023, 8:57pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/3 "2023-09-01T20:57:28Z")

</div>

Hey thanks for the update, it seems we need dfx 0.14.4 to fix this? So we are just waiting for the new dfx version and we can deploy the changes to our canisters?

---

<div class="post-metadata">

**Author:** ![anon74414410](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@anon74414410](https://forum.dfinity.org/u/anon74414410)\
**Post date:** [September 5, 2023, 7:07pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/4 "2023-09-05T19:07:30Z")

</div>

DFX isn’t required. You can edit your package.json or run `npm upgrade @dfinity/agent` to update your frontend code and get the latest patch at any time

---

<div class="post-metadata">

**Author:** ![Mitch](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mitch/32/4826_2.png) [@Mitch](https://forum.dfinity.org/u/Mitch)\
**Post date:** [September 5, 2023, 7:28pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/5 "2023-09-05T19:28:25Z")

</div>

Awesome, thanks @anon74414410!

---

<div class="post-metadata">

**Author:** ![Mitch](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mitch/32/4826_2.png) [@Mitch](https://forum.dfinity.org/u/Mitch)\
**Post date:** [September 14, 2023, 12:05pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/6 "2023-09-14T12:05:44Z")

</div>

Hey all, we’ve updated to the recommended specs and the “page failed to load error” has mostly gone away. We have noticed the issue persists for urls with different language chars:

 ![Screen Shot 2023-09-14 at 7.58.39 AM](https://us1.discourse-cdn.com/flex023/uploads/dfn/original/2X/c/c0a1fd61f69491f6df3592dca640b273477f220f.jpeg)

For example this [url](https://nuance.xyz/mujin0722/3888-zjfrd-tqaaa-aaaaf-qakia-cai/%E6%97%A0%E8%AE%BA%E7%BE%8E%E8%81%94%E5%82%A8%E6%98%AF%E5%90%A6%E5%8A%A0%E6%81%AFbtc%E4%BB%8D%E5%B0%86%E5%9B%9E%E5%88%B07%E4%B8%87%E5%88%80) has `无论美联储是否加息btc仍将回到7万刀` in it and does not work while this [url](https://nuance.xyz/nuance/3818-zjfrd-tqaaa-aaaaf-qakia-cai/introduction) works.

I also notice I can navigate through the UI in some cases, but as soon as I refresh the page the error returns.

---

<div class="post-metadata">

**Author:** ![peterparker](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@peterparker](https://forum.dfinity.org/u/peterparker)\
**Post date:** [September 14, 2023, 12:21pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/7 "2023-09-14T12:21:56Z")

</div>

Not entirely sure but, this looks like a similiar issue to the one I faced recently (it’s not related to agent-js) and which should be solved by a fix in the Boundary Nodes. Not sure if the fix is already in prod or scheduled to be deployed though but, the fix exists (if same issue).

@rbirkner @Kepler the “url decoding for encoded query strings” has be deployed?

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [September 14, 2023, 12:40pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/8 "2023-09-14T12:40:46Z")

</div>

This is unfortunately an additional edge case that we have not catered for, I’m looking for a solution now. Thanks for reporting @Mitch

---

<div class="post-metadata">

**Author:** ![Mitch](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/mitch/32/4826_2.png) [@Mitch](https://forum.dfinity.org/u/Mitch)\
**Post date:** [September 14, 2023, 1:39pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/9 "2023-09-14T13:39:30Z")

</div>

Sounds good, thanks for looking into it @peterparker / @NathanosDev

---

<div class="post-metadata">

**Author:** ![NathanosDev](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nathanosdev/32/7204_2.png) [@NathanosDev](https://forum.dfinity.org/u/NathanosDev)\
**Post date:** [September 14, 2023, 4:00pm UTC](https://forum.dfinity.org/t/upgrade-agent-js-to-resolve-a-chrome-issue/22364/10 "2023-09-14T16:00:09Z")

</div>

A fix is done and has started moving through the pipeline, I’ll update you once we’re releasing this.
