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

Authentication plan #25

Open
nihaals opened this issue Mar 3, 2021 · 6 comments
Open

Authentication plan #25

nihaals opened this issue Mar 3, 2021 · 6 comments

Comments

@nihaals
Copy link
Member

nihaals commented Mar 3, 2021

No description provided.

@nihaals
Copy link
Member Author

nihaals commented Mar 3, 2021

The first idea was to have a hacky generate endpoint which will use a session cookie to generate a token that can be used by the frontend and store this in local storage. After thinking about this more, this idea won't work as we will be doing SSR for mod pages so we can get SEO and dynamic meta tags for embeds and we won't be able to access local storage on the first navigation.

A solution could be only SSR public mods (private mods/communities could exist in the future) and if the package isn't found get the client to request from the API themselves using local storage, and if it's not found again, show a 404. This still feels quite hacky.

If we use a cookie, we need CSRF. We could have the API require CSRF only if the token is a user token (as opposed to a service account's token) or a session ID to allow the frontend and third parties to use the same API which is an OK solution but we would need to start generating CSRF tokens and embed them ourselves.

Maybe there's a better way?

@MythicManiac
Copy link
Member

MythicManiac commented Mar 3, 2021

After thinking about this more, this idea won't work as we will be doing SSR for mod pages

It will work, since SSR rendered content will be from the PoV of unauthenticated users

@nihaals
Copy link
Member Author

nihaals commented Mar 3, 2021

If we make sure:

  • IE is blocked
  • Every GET request is "safe" (does not change any state)
  • Every GET and POST request is JSON only (not sure how package upload will work with this)
  • Block AJAX requests from a different origin to the frontend
  • CORS is set

We may be able to avoid CSRF tokens when using cookie authentication, but we would need to make sure we had good tests for all of these. I haven't done much research into this topic before as I'm used to using CSRF tokens in templates so I would like to actually test this with a POC to make sure everything is as expected before fully implementing this.

@MythicManiac
Copy link
Member

I don't want to use cookie auth at all with the API if we can help it, and we shouldn't need to. For authed users we can always get a token via some channel, and unauthed users don't need a token.

@nihaals
Copy link
Member Author

nihaals commented Mar 4, 2021

It will work, since SSR rendered content will be from the PoV of unauthenticated users

So something like the first solution I described?

A solution could be only SSR public mods (private mods/communities could exist in the future) and if the package isn't found get the client to request from the API themselves using local storage, and if it's not found again, show a 404.

@MythicManiac
Copy link
Member

MythicManiac commented Mar 4, 2021

Yeah sounds about right. Additionally, we won't have "private" content any time soon since the CDN doesn't have access control, but we might have unlisted.

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

2 participants