Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure API endpoints with CORS #132

Open
antoninoLorenzo opened this issue Sep 11, 2024 · 0 comments
Open

Secure API endpoints with CORS #132

antoninoLorenzo opened this issue Sep 11, 2024 · 0 comments

Comments

@antoninoLorenzo
Copy link

I found that the api endpoints can be accessed easily from every host in the local network; for example accessing the history on http://HOST:8840/api/history/ is easy, we also get to know the ID field and this could be used on the other api endpoints.

I saw in the discussion that authentication, for now, isn't supported, however I think that starting to make the app more secure is important and could make the app more trusted.

What should change

Frontend
There are two api calls made on the frontend, inside index.js:

...
async function loadAddrs() {
    
    const url = '/api/all';
    addrsArray = await (await fetch(url)).json();
    bkpArray = addrsArray;

    field = localStorage.getItem("sortField");
    down = JSON.parse(localStorage.getItem("sortDown"));

    checkNotEmpty(addrsArray);
}

...
async function editForm(id, known) {
    
    const name = document.getElementById("name"+id).value;
    const url = '/api/edit/'+id+'/'+name+'/'+known;

    // console.log(url);

    await fetch(url);
}

There should be some endpoint exposed that internally makes requests to those api endpoints, for example /load (or similar) could be used for /api/all; I am still not sure about editForm.

Backend
Inside /internal/web/web.gui

func Gui(dirPath, nodePath string) {
...
	router := gin.New()
	router.Use(gin.Recovery())

I am still not familiar with gin, however the Recover middleware could be combined with a custom cors.New(cors.Config{...}) middleware in some way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant