-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[NoQA] Fix CHAI #82686
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
[NoQA] Fix CHAI #82686
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
306579d
add script to generate allowed external urls
rushatgabhane ad92f51
add ci step to generate ai allowed urls whitelist
rushatgabhane d8b019f
add allowed external urls list
rushatgabhane 5358a25
add dompurify cdn script tag
rushatgabhane 413b350
fetch allowed domains and filter external links
rushatgabhane 16dfa35
sanitize inner html with dompurify
rushatgabhane 2cba225
add script to generate allowed urls using ts-node
rushatgabhane fe12884
prettier
rushatgabhane 9a59b2a
Merge branch 'Expensify:main' into allowed-urls
rushatgabhane 890baf8
Fix ESLint errors in generateAllowedUrls.ts
MelvinBot 274a613
Update .github/scripts/generateAllowedUrls.ts
rushatgabhane 3fcc64d
style: switch to double quotes and tidy formatting
rushatgabhane e63478e
Merge branch 'allowed-urls' of github.com:rushatgabhane/exfy into all…
rushatgabhane 386aaa7
Merge branch 'main' into allowed-urls
rushatgabhane 337004c
style: switch to single quotes and tidy
rushatgabhane 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
|
|
||
| /** | ||
| * Script to extract all URLs from help articles and generate a whitelist. | ||
| * Run this at build time to update the allowed URLs list. | ||
| * | ||
| * Usage: npx ts-node .github/scripts/generateAllowedUrls.ts | ||
| */ | ||
|
|
||
| const DOCS_DIR = path.join(__dirname, '..', '..', 'docs'); | ||
| const OUTPUT_FILE = path.join(DOCS_DIR, 'assets', 'js', 'allowedExternalUrls.json'); | ||
|
|
||
| // Regex to match URLs in markdown | ||
| // Matches: [text](url), <url>, and bare URLs | ||
| const URL_PATTERNS = [ | ||
| /\[.*?\]\((https?:\/\/[^)\s]+)\)/g, // Markdown links [text](url) | ||
| /<(https?:\/\/[^>\s]+)>/g, // Angle bracket URLs <url> | ||
| /(?<![([])(https?:\/\/[^\s)\]>"']+)/g, // Bare URLs | ||
| ]; | ||
|
|
||
| function findMarkdownFiles(dir: string): string[] { | ||
| const files: string[] = []; | ||
| const items = fs.readdirSync(dir, {withFileTypes: true}); | ||
|
|
||
| for (const item of items) { | ||
| const fullPath = path.join(dir, item.name); | ||
| if (item.isDirectory() && !item.name.startsWith('_site')) { | ||
| files.push(...findMarkdownFiles(fullPath)); | ||
| } else if (item.isFile() && item.name.endsWith('.md')) { | ||
| files.push(fullPath); | ||
| } | ||
| } | ||
| return files; | ||
| } | ||
|
|
||
| function extractUrls(content: string): Set<string> { | ||
| const urls = new Set<string>(); | ||
|
|
||
| for (const pattern of URL_PATTERNS) { | ||
| const regex = new RegExp(pattern.source, pattern.flags); | ||
| let match = regex.exec(content); | ||
| while (match !== null) { | ||
| // Get the captured group (URL) or the full match | ||
| const url = match[1] || match[0]; | ||
| // Clean up trailing punctuation that might be captured | ||
| const cleanUrl = url.replace(/[.,;:!?)]+$/, ''); | ||
| if (cleanUrl.startsWith('http')) { | ||
| urls.add(cleanUrl); | ||
| } | ||
| match = regex.exec(content); | ||
| } | ||
| } | ||
| return urls; | ||
| } | ||
|
|
||
| function main() { | ||
| console.log('Scanning markdown files for URLs...'); | ||
|
|
||
| const allUrls = new Set<string>(); | ||
| const markdownFiles = findMarkdownFiles(DOCS_DIR); | ||
|
|
||
| console.log(`Found ${markdownFiles.length} markdown files`); | ||
|
|
||
| for (const file of markdownFiles) { | ||
| const content = fs.readFileSync(file, 'utf-8'); | ||
| const urls = extractUrls(content); | ||
| for (const url of urls) { | ||
| allUrls.add(url); | ||
| } | ||
| } | ||
|
|
||
| // Filter out Expensify URLs (check domain properly) and sort | ||
| const urlList = Array.from(allUrls) | ||
| .filter((url) => { | ||
| try { | ||
| const hostname = new URL(url).hostname; | ||
| return hostname !== 'expensify.com' && !hostname.endsWith('.expensify.com'); | ||
| } catch { | ||
| return false; | ||
| } | ||
| }) | ||
| .sort(); | ||
|
|
||
| console.log(`Found ${urlList.length} unique URLs`); | ||
|
|
||
| // Write to JSON file | ||
| fs.writeFileSync(OUTPUT_FILE, JSON.stringify(urlList, null, 2)); | ||
| console.log(`Written to ${OUTPUT_FILE}`); | ||
| } | ||
|
|
||
| main(); |
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 |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ _site | |
| .jekyll-metadata | ||
| vendor | ||
| _data/routes.yml | ||
| assets/js/allowedExternalUrls.json | ||
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
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
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.
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 allowlist check currently fails open:
allowedDomainsstarts empty and stays empty if/assets/js/allowedExternalUrls.jsonfails to load, and the guardallowedDomains.length > 0means non-Expensify links are not removed in that state. In any case where the JSON fetch is delayed or errors, AI responses can still render arbitrary external anchors, which defeats the security hardening this change is meant to provide.Useful? React with 👍 / 👎.
Uh oh!
There was an error while loading. Please reload this page.
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.
yeah that's fine. we don't wanna wait on it