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

Generate a Random OAuth State Each Time #246

Open
harshkhandeparkar opened this issue Nov 15, 2024 · 2 comments
Open

Generate a Random OAuth State Each Time #246

harshkhandeparkar opened this issue Nov 15, 2024 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@harshkhandeparkar
Copy link
Member

harshkhandeparkar commented Nov 15, 2024

Describe the feature/bug

The Github oauth flow has a state variable in its request that is supposed to be used to prevent CSRF. Currently, it is a constant string, but it should be randomly generated for each oauth login request.

In the case of KWoC, the oauth request only logs in the user and no damage could be done even if another site redirects to the oauth login url. However, it would be best to use a random string anyway.

Solution:

  1. Generate a random string when clicking on the login button
  2. Store the string in localstorage and redirect to the oauth URL with this state
  3. When the oauth login is complete and the user is redirected to /oauth on the frontend, match these strings and only proceed to log in if they match
  4. It would also be good to make the state a limited-time string so that a string generated previously cannot be used

Resources

export const GH_OAUTH_URL = `https://github.com/login/oauth/authorize?client_id=${GH_OAUTH_CLIENT_ID}&state=replacethiswithrandomtextlater`;

@harshkhandeparkar harshkhandeparkar added enhancement New feature or request good first issue Good for newcomers bug Something isn't working and removed enhancement New feature or request bug Something isn't working labels Nov 15, 2024
@itsarijitray
Copy link

@harshkhandeparkar Can I give this a shot?

@harshkhandeparkar
Copy link
Member Author

Sure @itsarijitray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants