-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add server-side URL proxy to bypass CORS when loading external data #247
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
Draft
Copilot
wants to merge
2
commits into
main
Choose a base branch
from
copilot/add-pendidikan-chart-visualization
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.
+146
−5
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { DataFormulatorState, dfActions, selectRefreshConfigs } from './dfSlice' | |
| import { AppDispatch } from './store'; | ||
| import { DictTable } from '../components/ComponentType'; | ||
| import { createTableFromText } from '../data/utils'; | ||
| import { fetchWithIdentity, getUrls, computeContentHash } from './utils'; | ||
| import { fetchWithIdentity, getUrls, computeContentHash, buildProxiedUrl } from './utils'; | ||
|
|
||
| interface RefreshResult { | ||
| tableId: string; | ||
|
|
@@ -55,7 +55,11 @@ export function useDataRefresh() { | |
| } | ||
|
|
||
| try { | ||
| const response = await fetch(source.url); | ||
| // For external http/https URLs, route through the backend proxy to avoid | ||
| // CORS failures (e.g. public S3 buckets without Access-Control-Allow-Origin). | ||
| const fetchUrl = buildProxiedUrl(source.url); | ||
|
|
||
| const response = await fetch(fetchUrl); | ||
| if (!response.ok) { | ||
| throw new Error(`HTTP ${response.status}: ${response.statusText}`); | ||
| } | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -73,9 +73,24 @@ export function getUrls() { | |
|
|
||
| // Workspace | ||
| OPEN_WORKSPACE: `/api/tables/open-workspace`, | ||
|
|
||
| // URL proxy - fetches external URLs server-side (bypasses browser CORS) | ||
| FETCH_URL_PROXY: `/api/tables/fetch-url`, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Build a fetch URL that routes external http/https URLs through the backend | ||
| * proxy to avoid CORS failures (e.g. public S3 buckets without CORS headers). | ||
| * Relative and non-http URLs are returned unchanged. | ||
| */ | ||
| export function buildProxiedUrl(url: string): string { | ||
| if (url.startsWith('http://') || url.startsWith('https://')) { | ||
| return `${getUrls().FETCH_URL_PROXY}?url=${encodeURIComponent(url)}`; | ||
| } | ||
| return url; | ||
| } | ||
|
|
||
| /** | ||
| * Get the current namespaced identity from the Redux store, or fall back to browser ID. | ||
| * Returns identity in "type:id" format (e.g., "user:alice@example.com" or "browser:550e8400-...") | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ import { DataSourceConfig, DictTable } from '../components/ComponentType'; | |
| import { createTableFromFromObjectArray, createTableFromText, loadTextDataWrapper, loadBinaryDataWrapper } from '../data/utils'; | ||
| import { DataLoadingChat } from './DataLoadingChat'; | ||
| import { DatasetSelectionView, DatasetMetadata } from './TableSelectionView'; | ||
| import { getUrls, fetchWithIdentity } from '../app/utils'; | ||
| import { getUrls, fetchWithIdentity, buildProxiedUrl } from '../app/utils'; | ||
| import { DBManagerPane } from './DBTableManager'; | ||
| import { MultiTablePreview } from './MultiTablePreview'; | ||
| import { | ||
|
|
@@ -821,7 +821,11 @@ export const UnifiedDataUploadDialog: React.FC<UnifiedDataUploadDialogProps> = ( | |
| const baseName = parts[parts.length - 1]?.split('?')[0] || 'dataset'; | ||
| const tableName = getUniqueTableName(baseName.replace(/\.[^.]+$/, ''), existingNames); | ||
|
|
||
| fetch(fullUrl) | ||
| // For external http/https URLs, route through the backend proxy to avoid | ||
| // CORS failures (e.g. public S3 buckets without Access-Control-Allow-Origin). | ||
| const fetchUrl = buildProxiedUrl(urlToUse) || fullUrl; | ||
|
|
||
| fetch(fetchUrl) | ||
| .then(res => { | ||
| if (!res.ok) { | ||
| throw new Error(`HTTP ${res.status}: ${res.statusText}`); | ||
|
|
||
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.
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Copilot Autofix
AI 18 days ago
In general, the fix is to ensure that detailed exception information (messages or stack traces) is only logged server-side and not returned to clients. The client should receive either a generic message or a carefully curated/sanitized message that cannot expose internal implementation details. Status codes can remain specific, but message bodies must be safe.
The best targeted fix here is to change
sanitize_db_error_messageso that, for unknown errors, it does not includeerror_msgin the returned string. Instead, it should return a static, generic error like"An unexpected error occurred."while still logging the full error withlogger.errorfor debugging. Optionally, to be extra safe, even the “safe” patterns can be changed to return generic messages rather than echoing the fullerror_msg, but the minimal change required to stop the identified leak is to fix the default branch at line 673. No changes are needed in the callers (e.g., at lines 629, 693, 939) because they already rely on this helper for sanitization and they log separately.Concretely, in
py-src/data_formulator/tables_routes.py, withinsanitize_db_error_message, keep converting the exception to a string and keep the pattern matching, but change the final return statement to droperror_msgfrom the message. Optionally, we can also slightly adjust the log to include more context (but still server-side only). This change requires no new imports or additional functions.