Skip to content
CCPEDIAby Unity Nodes
App Development

Cors issue with Daml Hub

9 posts844 views3 likesLast activity Sep 2022

  1. galiliyoOP

    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?

  2. Alex_Matson 1

    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

  3. galiliyo

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

  4. Alex_Matson 1

    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

  5. Jean_Safar1

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

  6. dtanabe

    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

  7. subashk 1

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

    Access-Control-Allow-Origin

  8. galiliyo

    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?

  9. ariscatan

    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