-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: critical security issue, where PAT was exposed #7
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bcf6f2c
fix: critical security vulnerabilities
webbertakken 65d682d
fix: security issue
webbertakken da03e0a
feat: implement split architecture for security
webbertakken 2158ace
feat: accept personalAccessToken from options for cleaner API
webbertakken 7feb53a
feat: use webpack DefinePlugin to exclude sensitive data from client …
webbertakken c853a12
revert: use environment variable approach for security
webbertakken a34113b
chore: fail if env variable is not provided
webbertakken ea58d37
feat: add proper description for people that upgrade
webbertakken eab1509
docs: update README for v4.0.0 security changes
webbertakken c1ac143
chore: formatting
webbertakken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { createContext, useContext, ReactNode } from 'react' | ||
import { GistsClient, RuntimeConfig } from './index' | ||
|
||
interface GistsContextType { | ||
client: GistsClient | ||
config: RuntimeConfig | ||
} | ||
|
||
const GistsContext = createContext<GistsContextType | undefined>(undefined) | ||
|
||
interface GistsProviderProps { | ||
children: ReactNode | ||
config: RuntimeConfig | ||
} | ||
|
||
export function GistsProvider({ children, config }: GistsProviderProps) { | ||
const client = new GistsClient(config) | ||
|
||
return ( | ||
<GistsContext.Provider value={{ client, config }}> | ||
{children} | ||
</GistsContext.Provider> | ||
) | ||
} | ||
|
||
export function useGists() { | ||
const context = useContext(GistsContext) | ||
if (context === undefined) { | ||
throw new Error('useGists must be used within a GistsProvider') | ||
} | ||
return context | ||
} | ||
|
||
export function useGistsClient() { | ||
const { client } = useGists() | ||
return client | ||
} | ||
|
||
export function useGistsConfig() { | ||
const { config } = useGists() | ||
return config | ||
} |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Client-side plugin component | ||
* This runs in the browser and has access to runtime configuration only | ||
*/ | ||
|
||
interface RuntimeConfig { | ||
enabled: boolean | ||
verbose: boolean | ||
gistListPageComponent: string | ||
gistPageComponent: string | ||
} | ||
|
||
class GistsClient { | ||
private config: RuntimeConfig | ||
|
||
constructor(config: RuntimeConfig) { | ||
this.config = config | ||
} | ||
|
||
// Client-side utility methods | ||
isEnabled(): boolean { | ||
return this.config.enabled | ||
} | ||
|
||
isVerbose(): boolean { | ||
return this.config.verbose | ||
} | ||
|
||
getGistListComponent(): string { | ||
return this.config.gistListPageComponent | ||
} | ||
|
||
getGistPageComponent(): string { | ||
return this.config.gistPageComponent | ||
} | ||
|
||
// Client-side analytics or tracking | ||
trackGistView(gistId: string): void { | ||
if (this.config.verbose) { | ||
console.log(`Viewing gist: ${gistId}`) | ||
} | ||
|
||
// Could send analytics events here | ||
// Note: No access to GitHub API tokens - this is client-side only | ||
} | ||
|
||
// Client-side URL helpers | ||
getGistUrl(gistId: string): string { | ||
return `/gists/${gistId}` | ||
} | ||
|
||
getGistListUrl(): string { | ||
return '/gists' | ||
} | ||
|
||
// Client-side search/filtering (if needed) | ||
filterGists(gists: any[], searchTerm: string): any[] { | ||
if (!searchTerm) return gists | ||
|
||
return gists.filter(gist => | ||
gist.description?.toLowerCase().includes(searchTerm.toLowerCase()) || | ||
Object.values(gist.files || {}).some((file: any) => | ||
file.filename?.toLowerCase().includes(searchTerm.toLowerCase()) | ||
) | ||
) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace Using - filterGists(gists: any[], searchTerm: string): any[] {
+ filterGists(gists: Gist[], searchTerm: string): Gist[] { You'll need to import the import type { Gist } from '../types' 🤖 Prompt for AI Agents
|
||
} | ||
|
||
// Export factory function | ||
export function createGistsClient(config: RuntimeConfig): GistsClient { | ||
return new GistsClient(config) | ||
} | ||
|
||
// Export types for theme components | ||
export type { RuntimeConfig } | ||
export { GistsClient } |
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,94 @@ | ||
import { Octokit } from 'octokit' | ||
import { throttling } from '@octokit/plugin-throttling' | ||
import { Authenticated, Gist, Gists } from '../types' | ||
|
||
type Props = { | ||
personalAccessToken: string | ||
} | ||
|
||
const OctokitWithThrottling = Octokit.plugin(throttling) | ||
|
||
export default class GitHub { | ||
private instance: InstanceType<typeof Octokit> | ||
private instance: InstanceType<typeof OctokitWithThrottling> | ||
private maxGists: number = 100 // Limit to prevent resource exhaustion | ||
|
||
constructor(props: Props) { | ||
const { personalAccessToken: auth } = props | ||
this.instance = new Octokit({ auth }) | ||
this.instance = new OctokitWithThrottling({ | ||
auth, | ||
throttle: { | ||
onRateLimit: (retryAfter: number, options: any) => { | ||
console.warn(`Request quota exhausted for request ${options.method} ${options.url}`) | ||
if (options.request.retryCount === 0) { | ||
console.log(`Retrying after ${retryAfter} seconds!`) | ||
return true | ||
} | ||
return false | ||
}, | ||
onSecondaryRateLimit: (retryAfter: number, options: any) => { | ||
console.warn(`Secondary rate limit detected for request ${options.method} ${options.url}`) | ||
return false | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
public async getAuthenticated(): Promise<Authenticated> { | ||
const response = await this.instance.rest.users.getAuthenticated() | ||
|
||
return response.data | ||
try { | ||
const response = await this.instance.rest.users.getAuthenticated() | ||
return response.data | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : 'Unknown error' | ||
console.error('Failed to authenticate with GitHub:', message) | ||
throw new Error('GitHub authentication failed. Please check your Personal Access Token.') | ||
} | ||
} | ||
|
||
public async getUsername() { | ||
const authenticated = await this.getAuthenticated() | ||
|
||
return authenticated?.login || null | ||
try { | ||
const authenticated = await this.getAuthenticated() | ||
return authenticated?.login || null | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : 'Unknown error' | ||
console.error('Failed to get username:', message) | ||
return null | ||
} | ||
} | ||
|
||
public async getMyGists(): Promise<Gists> { | ||
const response = await this.instance.rest.gists.list() | ||
try { | ||
const response = await this.instance.rest.gists.list({ | ||
per_page: this.maxGists, | ||
page: 1 | ||
}) | ||
|
||
const publicGists = response.data.filter((gist) => gist.public === true) | ||
|
||
if (publicGists.length === this.maxGists) { | ||
console.warn(`Gist limit of ${this.maxGists} reached. Some gists may not be included.`) | ||
} | ||
|
||
return response.data.filter((gist) => gist.public === true) | ||
return publicGists.slice(0, this.maxGists) | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : 'Unknown error' | ||
console.error('Failed to fetch gists:', message) | ||
return [] | ||
} | ||
} | ||
|
||
public async getGist(id: string): Promise<Gist> { | ||
const response = await this.instance.rest.gists.get({ gist_id: id }) | ||
// Validate gist ID format | ||
if (!id || !/^[a-f0-9]{32}$/.test(id)) { | ||
throw new Error(`Invalid gist ID format: ${id}`) | ||
} | ||
|
||
return response.data | ||
try { | ||
const response = await this.instance.rest.gists.get({ gist_id: id }) | ||
return response.data | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : 'Unknown error' | ||
console.error(`Failed to fetch gist ${id}:`, message) | ||
throw new Error(`Failed to fetch gist: ${message}`) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.