Is there any way to access secrets from a static html space (javascript)?

Hello,

I have a Huggingface static space that uses javascript. I know that space secrets are accessible as environment variables. Is there any way to access these secrets from javascript?

Thanks

Hi @Giustiniano,
Do you need the secrets at build time? If not, please note that you cannot store secrets in a static web page. This is because the requests and code on the page are public, allowing anyone to inspect the code and access the secret. To keep your secret secure, you may need to use a backend proxy.

In my case, there’s no build time, it’s a static page with vanilla JS. I was wondering if there was a way to access the environment variables from javascript, maybe with a huggingface spaces api

You can set secrets via API, but I don’t think you can retrieve it unless you’re inside a Gradio/Streamlit/Docker SDK. Since if you use a Secret on a static page, it won’t be secret anymore.

1 Like