-
-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: resolve provider validation and CORS issues in dev mode #1759
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2072,6 +2072,10 @@ export const useProvidersStore = defineStore('providers', () => { | |
| if (!providerMetadata[providerId] || intervalMs <= 0) | ||
| continue | ||
|
|
||
| // Only start periodic validation for providers that have been explicitly added | ||
| if (!addedProviders.value[providerId]) | ||
| continue | ||
|
|
||
| if (providerRevalidationLoops.has(providerId)) { | ||
| continue | ||
| } | ||
|
|
@@ -2087,8 +2091,8 @@ export const useProvidersStore = defineStore('providers', () => { | |
| // Update configuration status for all configured providers | ||
| async function updateConfigurationStatus() { | ||
| await Promise.all(Object.entries(providerMetadata) | ||
| // TODO: ignore un-configured provider | ||
| // .filter(([_, provider]) => provider.configured) | ||
| // Only validate providers that have been explicitly added by the user | ||
| .filter(([providerId]) => addedProviders.value[providerId]) | ||
| .map(async ([providerId]) => { | ||
| try { | ||
| if (providerRuntimeState.value[providerId]) { | ||
|
|
@@ -2108,6 +2112,23 @@ export const useProvidersStore = defineStore('providers', () => { | |
| watch(providerCredentials, updateConfigurationStatus, { deep: true, immediate: true }) | ||
| startPeriodicRuntimeValidation() | ||
|
|
||
| // Watch for newly added providers and start their periodic validation | ||
| watch(addedProviders, (newAdded, oldAdded) => { | ||
| for (const providerId of Object.keys(newAdded)) { | ||
| if (newAdded[providerId] && !oldAdded?.[providerId]) { | ||
|
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.
Useful? React with 👍 / 👎. |
||
| // Provider was just added, start its periodic validation if configured | ||
| const intervalMs = providerValidationIntervalMsById.get(providerId) | ||
| if (intervalMs && intervalMs > 0 && !providerRevalidationLoops.has(providerId)) { | ||
| const loop = useIntervalFn(() => { | ||
| void validateProvider(providerId, { force: true }) | ||
| }, intervalMs, { immediate: false, immediateCallback: false }) | ||
| loop.resume() | ||
| providerRevalidationLoops.set(providerId, loop) | ||
| } | ||
| } | ||
| } | ||
| }, { deep: true }) | ||
|
Comment on lines
+2116
to
+2130
Contributor
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. This watch(addedProviders, (newAdded, oldAdded) => {
const allIds = new Set([...Object.keys(newAdded), ...Object.keys(oldAdded || {})]);
for (const providerId of allIds) {
const isNew = newAdded[providerId];
const wasOld = oldAdded?.[providerId];
if (isNew && !wasOld) {
// Provider was just added, start its periodic validation if configured
const intervalMs = providerValidationIntervalMsById.get(providerId);
if (intervalMs && intervalMs > 0 && !providerRevalidationLoops.has(providerId)) {
const loop = useIntervalFn(() => {
void validateProvider(providerId, { force: true });
}, intervalMs, { immediate: false, immediateCallback: false });
loop.resume();
providerRevalidationLoops.set(providerId, loop);
}
} else if (!isNew && wasOld) {
// Provider was removed, stop its periodic validation
const loop = providerRevalidationLoops.get(providerId);
if (loop) {
(loop as { pause: () => void }).pause();
providerRevalidationLoops.delete(providerId);
}
}
}
}, { deep: true })References
|
||
|
|
||
| watch(() => authState.isAuthenticated, updateConfigurationStatus) | ||
|
|
||
| // Available providers (only those that are properly configured) | ||
|
|
||
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.
Disabling
webSecurityis a significant security risk, even in development mode. It makes your application vulnerable to cross-site scripting (XSS) attacks if it loads any third-party content in the renderer. While convenient for bypassing CORS issues, a more secure and production-like approach is to proxy requests through the main process. The main process is not subject to CORS, so it can safely fetch data from external APIs and forward it to the renderer process via IPC. This keepswebSecurityenabled, hardening your app against potential vulnerabilities.