-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfb3fd9
commit 3a16733
Showing
9 changed files
with
156 additions
and
60 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Re2 from "re2"; | ||
import axios from "axios"; | ||
import { Detector, ScanResult } from "../../types/detector"; | ||
|
||
const keywords: string[] = ["ya29."]; | ||
const keyPattern = new Re2(/ya29\.[\w\-\.]+/, "gi"); | ||
|
||
const scan = async ( | ||
verify: boolean | undefined, | ||
data: string | ||
): Promise<ScanResult | null> => { | ||
const matches = data.matchAll(keyPattern); | ||
let result: ScanResult = { detectorType: "Google Oauth2", verified: false }; | ||
|
||
for (const match of matches) { | ||
if (!match) continue; | ||
const resMatch = match[0].trim(); | ||
result.rawValue = resMatch; | ||
result.position = match.index; | ||
|
||
if (verify) { | ||
try { | ||
const { data } = await axios.get( | ||
`https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=${resMatch}` | ||
); | ||
|
||
result.verified = true; | ||
} catch (error) {} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
const detectorType = "GOOGLE_OAUTH2_DETECTOR"; | ||
|
||
export const GoogleOauth2Detector: Detector = { | ||
scan, | ||
keywords, | ||
detectorType, | ||
}; |
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
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
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
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
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