-
Notifications
You must be signed in to change notification settings - Fork 137
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 2 commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -64,24 +64,22 @@ class GitHubService { | |||||
| private readonly CACHE_KEY = "github_org_stats"; | ||||||
| private readonly CACHE_DURATION = 30 * 60 * 1000; // 30 minutes in milliseconds | ||||||
| private readonly BASE_URL = "https://api.github.com"; | ||||||
| private readonly DISCUSSIONS_UNAVAILABLE_MESSAGE = | ||||||
| "GitHub Discussions are disabled until a server-side GitHub proxy is configured."; | ||||||
|
||||||
| "GitHub Discussions are disabled until a server-side GitHub proxy is configured."; | |
| "GitHub Discussions are available only server-side; configure GITHUB_TOKEN or a server-side GitHub proxy."; |
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 , I had a quick question for you . is this gonna work around the discussions also , ATM the discussion in prod are working fine .
Copilot
AI
Apr 18, 2026
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 removes Authorization, but this service makes requests to https://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 to 0 discussions / 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
Copilot
AI
Apr 23, 2026
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.
getDiscussionsCount() returns 0 when GraphQL is unavailable in the browser. That makes downstream UI/reporting treat the value as a real count ("0 discussions") rather than "unavailable", which is misleading. Consider representing this as null/undefined (and updating GitHubOrgStats + UI), or surfacing an explicit "unavailable" flag/message instead of overloading 0.
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 this can be doable
Copilot
AI
Apr 23, 2026
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.
Even when canUseGitHubGraphQL() is true, fetchDiscussions() still calls https://api.github.com/graphql directly without any auth header. If/when this is invoked in a server-side context, it will still fail with 401 unless you route through an authenticated proxy or add server-side auth (e.g., from env). Consider failing fast with a clear configuration error when no server-side token/proxy is available, rather than attempting the call.
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.
@copilot apply changes based on this feedback
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,9 +221,13 @@ const isPRInTimeRange = (mergedAt: string, filter: TimeFilter): boolean => { | |
| const prDate = new Date(mergedAt); | ||
| return prDate >= filterDate; | ||
| }; | ||
| ``` | ||
|
|
||
| Computed Contributors | ||
| This is where React's useMemo shines: | ||
| typescriptconst contributors = useMemo(() => { | ||
|
|
||
| ```typescript | ||
| const contributors = useMemo(() => { | ||
| if (!allContributors.length) return []; | ||
|
|
||
| const filteredContributors = allContributors | ||
|
|
@@ -573,7 +577,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 +592,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 new
markdown.hooks.onBrokenMarkdownLinksconfig is likely not a recognized Docusaurus option (Docusaurus 3.x supportsonBrokenMarkdownLinksas a top-level config). As written, this may be ignored and broken markdown links will use the default behavior instead ofwarn. Consider moving this toonBrokenMarkdownLinks: "warn"at the top level and removing themarkdown.hooksnesting.