-
Notifications
You must be signed in to change notification settings - Fork 3
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
Require API key for requests #81
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We should not merge this PR until we have sorted out why the 2i2c server is not consistently writing to the db. (Else we won't know if things aren't working because we set up the API keys incorrectly or because the original 2i2c server issue is still present). |
…ronment variable.
Carifio24
changed the title
Require API key for non-read requests
Require API key for requests
Oct 10, 2023
After internal discussion, we've decided to lock down |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an API key layer to the backend server. Essentially, non-read (i.e. non-
GET
) request that comes into the server now requires a valid API key to actually get handled. The idea is that, while our data is free to be viewed by anyone, we really only want CosmicDS client applications (e.g. data stories, the main website) to be doing anything that modifies the database. A client application will need to put the API key into its authorization header.The way this is set up, API keys are generated offline using a method that I won't detail here - suffice it to say that there is no relationship between a client and the key that it gets. These keys are then hashed and stored in a database table. This way, even if an attacker got access to our database, they wouldn't actually be able to get the API keys. My plan is to have a different API key for each story/other client application so that, if necessary, we can track where requests are coming from.
One thing that this doesn't implement, but that I'm looking into, is the ability to persist sessions for our clients so that we don't need to query the API key table on each request. This shouldn't be a huge overhead right now, as the table is currently small and there's a unique index on the hashed key field, but it would be nice to have.
CC @nmearl and @johnarban since this would affect any requests coming from e.g. a Solara page.