LogoRobo.js

Proxy

Handle Discord's Content Security Policy in your activity

The Discord Proxy enforces a strict Content Security Policy (CSP) — a browser security mechanism that controls which URLs your app can load resources from — on all activities. Understanding these rules is essential for loading external resources.

Content Security Policy

CSP restricts which resources an activity can load. Discord only allows requests to your application's origin and mapped domains. External URLs, inline scripts, and unauthorized domains are blocked.

Proxy Rules

RuleDescription
No external URLsDirect requests to external domains are blocked
HTTPS onlyAll requests must use HTTPS
/.proxy prefixInternal requests use the /.proxy path prefix
Per-app CSPEach application has a unique CSP directive

Browser DevTools console showing Content Security Policy violation errors when an activity tries to load resources from an unmapped external domain

FocusCSP error messages in the browser console showing blocked requestsZoom100%NotesShow Chrome DevTools console with CSP violation errors. Red error text with 'Refused to load' messages. Helps developers recognize CSP issues.

@robojs/patch

@robojs/patch provides automatic URL patching via a Vite plugin. It is pre-installed in all activity templates and requires zero configuration.

config/vite.mjs
import { DiscordProxy } from '@robojs/patch'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [react(), DiscordProxy.Vite()]
})
config/vite.mjs
import { DiscordProxy } from '@robojs/patch'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [react(), DiscordProxy.Vite()]
})

URL Mapping

Configure URL mappings in the Discord Developer Portal under your application's URL Mappings section. Each mapping associates a path prefix with an external origin.

PrefixTarget
/google-fontshttps://fonts.googleapis.com
/cdnhttps://cdn.example.com

Use mapped paths in your code:

src/app/Activity.tsx
fetch('/google-fonts/css2?family=Inter')
src/app/Activity.jsx
fetch('/google-fonts/css2?family=Inter')

Discord Developer Portal URL Mappings section showing multiple prefix-to-target mappings for external services like Google Fonts and a CDN

FocusMultiple URL mapping entries configured in the Developer PortalZoom100%NotesShow URL Mappings with at least three entries: '/' root, '/google-fonts' to fonts.googleapis.com, '/cdn' to cdn.example.com. Include the 'Add' button.

URL Patching

Most developers don't need this — DiscordProxy.Vite() handles URL rewriting automatically. This section is for cases where third-party libraries use hardcoded domains that the Vite plugin can't reach.

patchUrlMappings() from @discord/embedded-app-sdk rewrites URLs in third-party libraries that have hardcoded domains:

src/app/App.tsx
import { patchUrlMappings } from '@discord/embedded-app-sdk'

patchUrlMappings([{ prefix: '/google-fonts', target: 'fonts.googleapis.com' }])
src/app/App.jsx
import { patchUrlMappings } from '@discord/embedded-app-sdk'

patchUrlMappings([{ prefix: '/google-fonts', target: 'fonts.googleapis.com' }])

Custom Proxy Server

For reaching services that Discord's URL Mappings cannot handle (such as specific ports, unsupported protocols, or dynamic URLs), create a custom proxy endpoint:

src/api/proxy.ts
import type { RoboRequest } from '@robojs/server'

export default async (req: RoboRequest) => {
  const url = req.query.url as string
  return fetch(url)
}
src/api/proxy.js
export default async (req) => {
  const url = req.query.url
  return fetch(url)
}

Validate and sanitize the target URL to prevent URL injection and SSRF attacks.

Network Limitations

ProtocolSupported
HTTPSYes
WebSocketYes
DASH / HLSYes
WebRTCNo
WebTransportNo

Security

The proxy hides user IP addresses. Since the SDK runs in the user's browser, a malicious user could modify the data it reports. Do not trust data from the Embedded App SDK as authoritative. Always validate server-side using the OAuth2 access token from authentication.

Next Steps

On this page