-
Notifications
You must be signed in to change notification settings - Fork 464
Fix ghs_ token regex: rebuild lib/ bundle and add missing hyphen #3932
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
615a713
df3ab55
b53799f
31e72ce
c90844a
eee6a34
85df3c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,15 +55,15 @@ const GITHUB_TOKEN_PATTERNS: TokenPattern[] = [ | |
| }, | ||
| { | ||
| type: TokenType.ServerToServer, | ||
| pattern: /\bghs_[a-zA-Z0-9]{36}\b/g, | ||
| pattern: /ghs_[A-Za-z0-9._-]{36,}/g, | ||
|
Member
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. Copilot is correct. For our use case(s), we would not want this to be unconstrained. |
||
| }, | ||
| { | ||
| type: TokenType.Refresh, | ||
| pattern: /\bghr_[a-zA-Z0-9]{36}\b/g, | ||
| }, | ||
| { | ||
| type: TokenType.AppInstallationAccess, | ||
| pattern: /\bghs_[a-zA-Z0-9]{255}\b/g, | ||
| pattern: /ghs_[A-Za-z0-9._-]{36,}/g, | ||
|
hagould marked this conversation as resolved.
Outdated
|
||
| }, | ||
|
hagould marked this conversation as resolved.
Outdated
|
||
| ]; | ||
|
|
||
|
|
@@ -109,16 +109,27 @@ function scanFileForTokens( | |
| logger: Logger, | ||
| ): TokenFinding[] { | ||
| const findings: TokenFinding[] = []; | ||
| const seenMatches = new Set<number>(); | ||
|
hagould marked this conversation as resolved.
Outdated
hagould marked this conversation as resolved.
Outdated
|
||
| try { | ||
| const content = fs.readFileSync(filePath, "utf8"); | ||
|
|
||
| for (const { type, pattern } of GITHUB_TOKEN_PATTERNS) { | ||
| const matches = content.match(pattern); | ||
| if (matches) { | ||
| for (let i = 0; i < matches.length; i++) { | ||
| findings.push({ tokenType: type, filePath: relativePath }); | ||
| const regex = new RegExp(pattern.source, pattern.flags); | ||
| let matchCount = 0; | ||
|
|
||
| for (const match of content.matchAll(regex)) { | ||
| const index = match.index; | ||
| if (index === undefined || seenMatches.has(index)) { | ||
| continue; | ||
| } | ||
| logger.debug(`Found ${matches.length} ${type}(s) in ${relativePath}`); | ||
|
|
||
| seenMatches.add(index); | ||
| findings.push({ tokenType: type, filePath: relativePath }); | ||
| matchCount++; | ||
|
hagould marked this conversation as resolved.
Outdated
|
||
| } | ||
|
hagould marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (matchCount > 0) { | ||
| logger.debug(`Found ${matchCount} ${type}(s) in ${relativePath}`); | ||
|
Member
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. Could you explain what the goal of these changes is in relation to the objectives of the PR?
Author
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.
Updated to
They were added to handle overlapping patterns between ServerToServer and AppInstallationAccess, but since those are now collapsed into a single pattern, they're no longer needed. |
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.