Skip to content
Discussions/App Development/Cors issue with Daml HubForum ↗

Cors issue with Daml Hub

App Development9 posts784 views3 likesLast activity Sep 2022
GA
galiliyoOP
Apr 2022

I am trying to access my ledger on Daml Hub using a React UI and a daml/react useQuery hook but I receive a CORS error.

Access to XMLHttpRequest at 'https://z5j8xs27k1s3edld.daml.app/v1/query' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Using Postman I can access the ledger as expected.
How do I fix this CORS issue?

AL
Alex_Matson
Apr 2022

Hi @galiliyo ,

It seems like you’re running your UI on a local server. In order to call Daml Hub API endpoints from a browser, the UI must be hosted and running on its Daml Hub domain. The documentation explains how to package and upload your UI to Hub: https://hub.daml.com/docs/quickstart#app-ui

If you’re interested in testing your application in a local development environment, you should run the UI against a local Daml sandbox ledger

GA
galiliyo
Aug 2022

So there is no option to deploy the UI outside of Daml Hub?

AL
Alex_Matson
Aug 2022

Correct: If your UI runs against Hub-hosted ledgers, and requires users to log in to Hub (in order to get ledger party JWT tokens), then the UI has to also be running on Hub

JE
Jean_Safar1
Aug 2022

but in that case the UI on the local server does have the token. So why shouldn’t that be enough?

DT
dtanabe
Aug 2022

It’s generally viewed as a security risk to allow exfiltration of tokens from one website to another.

MDN provides some technical background on why browsers enforce these kinds of restrictions: Cross-Origin Resource Sharing (CORS) - HTTP | MDN

SU
subashk
Aug 2022

Can’t we add specific domain to the ledgers to allow cross domain?

Access-Control-Allow-Origin

GA
galiliyo
Aug 2022

Apart from having a closed list of Allowed Origins, doesn’t the PKCE Authorization Flow mitigate the security risks associated with sharing JWTs and Authorization Codes?

AR
ariscatan
Sep 2022

Hi,
I have this issue quite a while. So it means there is no way I can host my UI on our server and call damlhub ledger api?

Or is there any way I can integrate a ledger app in our existing website?

Thanks

← Back to Discussions