
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@curia_/iframe-api-proxy
Advanced tools
API proxy system for iframe-based applications to bypass CSP (Content Security Policy) restrictions.
When embedding iframe applications on customer websites, strict CSP policies prevent direct API calls from the customer page to external domains. This package provides a robust solution by routing API requests through same-domain iframes.
Customer Website (strict CSP)
↓ embed.js tries to call API
fetch(https://api.example.com) ← BLOCKED by CSP
Customer Website
↓ embed.js uses proxy
PostMessage → iframe (same domain)
↓ iframe makes API call
fetch(https://api.example.com) ← ALLOWED
↓ response via PostMessage
Customer Website ← API Response
yarn add @curia_/iframe-api-proxy
import { ApiProxyClient } from '@curia_/iframe-api-proxy';
// Initialize proxy client
const proxyClient = new ApiProxyClient({
debug: true,
defaultTimeout: 10000
});
// Set active iframe for API requests
proxyClient.setActiveIframe(myIframeElement);
// Make API request (proxied through iframe)
const response = await proxyClient.makeApiRequest({
method: 'getUserInfo',
userId: 'user123',
communityId: 'community456'
});
import { ApiProxyServer } from '@curia_/iframe-api-proxy';
// Initialize proxy server
const proxyServer = new ApiProxyServer({
baseUrl: 'https://api.example.com',
debug: true
});
// Server automatically handles incoming proxy requests
// and makes actual API calls to the baseUrl
Client-side component that runs in the customer page context.
new ApiProxyClient(config?: ProxyClientConfig)
setActiveIframe(iframe: HTMLIFrameElement)
- Set the active iframe for API requestsmakeApiRequest(request: ApiRequest)
- Make an API request through the proxygetStatus()
- Get proxy client status and statisticsdestroy()
- Clean up resourcesinterface ProxyClientConfig {
defaultTimeout?: number; // Default: 10000ms
maxRetries?: number; // Default: 3
retryDelay?: number; // Default: 1000ms
debug?: boolean; // Default: false
requestIdPrefix?: string; // Default: 'proxy'
}
Server-side component that runs inside iframe contexts.
new ApiProxyServer(config: ProxyServerConfig)
getStatus()
- Get proxy server status and statisticsdestroy()
- Clean up resourcesinterface ProxyServerConfig {
baseUrl: string; // Required: API base URL
timeout?: number; // Default: 30000ms
debug?: boolean; // Default: false
headers?: Record<string, string>; // Custom headers
allowedOrigins?: string[]; // Security whitelist
serverId?: string; // Custom server ID
}
// In your embed script (customer page)
import { ApiProxyClient } from '@curia_/iframe-api-proxy';
class InternalPluginHost {
private apiProxy: ApiProxyClient;
constructor() {
this.apiProxy = new ApiProxyClient({ debug: true });
}
private async handleApiRequest(request: any): Promise<any> {
// Use proxy instead of direct fetch
return await this.apiProxy.makeApiRequest(request);
}
private switchToForum(iframe: HTMLIFrameElement): void {
// Set active iframe for API proxy
this.apiProxy.setActiveIframe(iframe);
}
}
// In your iframe application
import { ApiProxyServer } from '@curia_/iframe-api-proxy';
// Initialize when iframe loads
if (window !== window.parent) {
const proxyServer = new ApiProxyServer({
baseUrl: 'https://api.example.com',
debug: true
});
// Server automatically handles proxy requests
console.log('Proxy server ready:', proxyServer.getStatus());
}
const client = new ApiProxyClient({ debug: true });
const server = new ApiProxyServer({ baseUrl: 'https://api.example.com', debug: true });
// Client status
const clientStatus = client.getStatus();
console.log('Pending requests:', clientStatus.pendingRequestCount);
console.log('Average response time:', clientStatus.averageResponseTime);
// Server status
const serverStatus = server.getStatus();
console.log('Total requests:', serverStatus.requestCount);
console.log('Error count:', serverStatus.errorCount);
1. Forum iframe → ApiProxyClient (via PostMessage)
2. ApiProxyClient → Active iframe (via PostMessage)
3. Active iframe → ApiProxyServer (internal handling)
4. ApiProxyServer → API endpoint (via fetch)
5. API endpoint → ApiProxyServer (HTTP response)
6. ApiProxyServer → ApiProxyClient (via PostMessage)
7. ApiProxyClient → Forum iframe (via PostMessage)
This package is part of the Curia ecosystem. For contributions:
MIT License - see LICENSE file for details.
@curia/host-service
- Host service for community forums@curia/forum-app
- Forum application@curia/embed-sdk
- Embedding SDK for customersBuilt with ❤️ by the Curia team
FAQs
Cross-iframe API proxy for CSP-compliant communication
We found that @curia_/iframe-api-proxy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.