-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Remediate audit findings, replace vulnerable Firecrawl SDK, and harden release validation #1030
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
Open
jatmn
wants to merge
6
commits into
Gitlawb:main
Choose a base branch
from
hicap-oss:deps-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4108906
Harden release publish checks and remove vulnerable Firecrawl SDK
jatmn f2b83c5
Harden Bun test isolation for release validation
jatmn 232afcf
Complete execa mock coverage in user test
jatmn 12744d7
Preserve full module surfaces in user test mocks
jatmn dbf93c0
Override ip-address to 10.2.0
jatmn 768dffd
Merge upstream/main into deps-update
jatmn 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,133 @@ | ||
| import { afterEach, describe, expect, mock, test } from 'bun:test' | ||
|
|
||
| import { firecrawlScrape, firecrawlSearch } from './client.js' | ||
|
|
||
| const originalFetch = globalThis.fetch | ||
| const originalEnv = { | ||
| FIRECRAWL_API_KEY: process.env.FIRECRAWL_API_KEY, | ||
| FIRECRAWL_API_URL: process.env.FIRECRAWL_API_URL, | ||
| } | ||
|
|
||
| function restoreEnv(key: string, value: string | undefined): void { | ||
| if (value === undefined) { | ||
| delete process.env[key] | ||
| } else { | ||
| process.env[key] = value | ||
| } | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| globalThis.fetch = originalFetch | ||
| restoreEnv('FIRECRAWL_API_KEY', originalEnv.FIRECRAWL_API_KEY) | ||
| restoreEnv('FIRECRAWL_API_URL', originalEnv.FIRECRAWL_API_URL) | ||
| }) | ||
|
|
||
| describe('firecrawl client', () => { | ||
| test('search posts to the v2 API with bearer auth', async () => { | ||
| process.env.FIRECRAWL_API_KEY = 'fc-test-key' | ||
| delete process.env.FIRECRAWL_API_URL | ||
|
|
||
| globalThis.fetch = mock(async (input, init) => { | ||
| expect(String(input)).toBe('https://api.firecrawl.dev/v2/search') | ||
| expect(init?.method).toBe('POST') | ||
| expect((init?.headers as Record<string, string>).Authorization).toBe('Bearer fc-test-key') | ||
|
|
||
| const body = JSON.parse(String(init?.body)) as Record<string, unknown> | ||
| expect(body).toMatchObject({ | ||
| query: 'openclaude', | ||
| limit: 7, | ||
| origin: 'openclaude', | ||
| }) | ||
|
|
||
| return new Response( | ||
| JSON.stringify({ | ||
| success: true, | ||
| data: { | ||
| web: [{ url: 'https://example.com', title: 'Example', description: 'desc' }], | ||
| }, | ||
| }), | ||
| { status: 200, headers: { 'Content-Type': 'application/json' } }, | ||
| ) | ||
| }) as typeof globalThis.fetch | ||
|
|
||
| await expect(firecrawlSearch('openclaude', { limit: 7 })).resolves.toEqual({ | ||
| web: [{ url: 'https://example.com', title: 'Example', description: 'desc' }], | ||
| }) | ||
| }) | ||
|
|
||
| test('scrape allows self-hosted api urls without an api key', async () => { | ||
| delete process.env.FIRECRAWL_API_KEY | ||
| process.env.FIRECRAWL_API_URL = 'https://self-hosted.firecrawl.dev' | ||
|
|
||
| globalThis.fetch = mock(async (input, init) => { | ||
| expect(String(input)).toBe('https://self-hosted.firecrawl.dev/v2/scrape') | ||
| expect((init?.headers as Record<string, string>).Authorization).toBeUndefined() | ||
|
|
||
| const body = JSON.parse(String(init?.body)) as Record<string, unknown> | ||
| expect(body).toMatchObject({ | ||
| url: 'https://example.com', | ||
| formats: ['markdown'], | ||
| origin: 'openclaude', | ||
| }) | ||
|
|
||
| return new Response( | ||
| JSON.stringify({ | ||
| success: true, | ||
| data: { | ||
| markdown: '# Example', | ||
| }, | ||
| }), | ||
| { status: 200, headers: { 'Content-Type': 'application/json' } }, | ||
| ) | ||
| }) as typeof globalThis.fetch | ||
|
|
||
| await expect(firecrawlScrape('https://example.com')).resolves.toEqual({ | ||
| markdown: '# Example', | ||
| }) | ||
| }) | ||
|
|
||
| test('cloud api requires an api key', async () => { | ||
| delete process.env.FIRECRAWL_API_KEY | ||
| delete process.env.FIRECRAWL_API_URL | ||
|
|
||
| await expect(firecrawlSearch('openclaude')).rejects.toThrow( | ||
| 'Firecrawl API key is required for the cloud API.', | ||
| ) | ||
| }) | ||
|
|
||
| test('retries transient 502 responses before succeeding', async () => { | ||
| process.env.FIRECRAWL_API_KEY = 'fc-test-key' | ||
| delete process.env.FIRECRAWL_API_URL | ||
|
|
||
| let attempts = 0 | ||
| globalThis.fetch = mock(async () => { | ||
| attempts += 1 | ||
| if (attempts < 3) { | ||
| return new Response( | ||
| JSON.stringify({ | ||
| success: false, | ||
| error: 'temporary upstream failure', | ||
| }), | ||
| { status: 502, headers: { 'Content-Type': 'application/json' } }, | ||
| ) | ||
| } | ||
|
|
||
| return new Response( | ||
| JSON.stringify({ | ||
| success: true, | ||
| data: { | ||
| web: [{ url: 'https://example.com/retried' }], | ||
| }, | ||
| }), | ||
| { status: 200, headers: { 'Content-Type': 'application/json' } }, | ||
| ) | ||
| }) as typeof globalThis.fetch | ||
|
|
||
| await expect( | ||
| firecrawlSearch('openclaude', { maxRetries: 3, backoffFactorSeconds: 0 }), | ||
| ).resolves.toEqual({ | ||
| web: [{ url: 'https://example.com/retried' }], | ||
| }) | ||
| expect(attempts).toBe(3) | ||
| }) | ||
| }) |
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.