-
Notifications
You must be signed in to change notification settings - Fork 138
fix: stop exposing client-side tokens #1329
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
Changes from 1 commit
a2b6a8c
8f47c28
fb43872
0190eea
23c4c6b
68e12b8
39de21a
07f6eda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -573,7 +573,7 @@ Response Example: | |
| } | ||
| ``` | ||
| #### Authentication | ||
| All requests require a GitHub Personal Access Token: | ||
| Authenticated requests should be made from a server-side endpoint or serverless function so the token is never shipped to the browser: | ||
| ```typescript | ||
| const headers: Record<string, string> = { | ||
| Authorization: `token ${YOUR_GITHUB_TOKEN}`, | ||
|
|
@@ -588,22 +588,7 @@ Select scopes: public_repo, read:org | |
| Copy the token (you won't see it again!) | ||
|
Comment on lines
592
to
595
|
||
|
|
||
| #### Storing the Token: | ||
| In Docusaurus, we store it in docusaurus.config.js: | ||
| ```javascript | ||
| module.exports = { | ||
| customFields: { | ||
| gitToken: process.env.GITHUB_TOKEN || '', | ||
| }, | ||
| // ... | ||
| }; | ||
| ``` | ||
| Then access it: | ||
| ```typescript | ||
| const { | ||
| siteConfig: { customFields }, | ||
| } = useDocusaurusContext(); | ||
| const token = customFields?.gitToken || ""; | ||
| ``` | ||
| Do not store a GitHub token in `docusaurus.config.js` or any other client-bundled config. Keep it in server-side environment variables and call GitHub from a backend endpoint instead. | ||
|
sanjay-kv marked this conversation as resolved.
Outdated
|
||
| #### Error Handling | ||
| **Rate Limit Exceeded (403)** | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
getHeaders()change removesAuthorization, but this service makes requests tohttps://api.github.com/graphql(e.g., discussions count / discussions list). GitHub’s GraphQL API requires authentication, so these calls will now consistently fail (401) and the code will fall back to0discussions / mock discussions. Consider moving GraphQL calls behind a server-side endpoint (preferred), or switch to unauthenticated REST endpoints, or gate/disable these GraphQL features when no server-side auth is available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abhash-Chakraborty look into this