Activity Proxy Considerations
All network traffic is routed through the Discord Proxy for various security reasons. Under the hood we utilize Cloudflare Workers, which brings some restrictions, outlined below.WebTransport
While we currently only support websockets, we’re working with our upstream providers to enable WebTransport.WebRTC
WebRTC is not supported.Construct A Full URL
There are scenarios where instead of using a relative url (/path/to/my/thing) you may want or need to reference the full url when making a network request. The URL is a combination of the following
- The protocol you wish to use
- Your application’s client id
- The discord proxy domain
- Whatever you need to list
12345678
| Relative Path | Full Path | 
|---|---|
| /foo/bar.jpg | https://12345678.discordsays.com/foo/bar.jpg | 
Using External Resources
Activities in Discord are “sandboxed” via a Discord proxy. This is done to hide the users’ IP addresses as well as block URLs from known malicious endpoints. To achieve this, the Discord Developer Portal has a section for configuring URL Mappings for your application. One edge-case of URL mappings is that third-party NPM modules or other resources may reference external (non-sandboxed) urls. For example, if your application has an npm module that attempts to make an http request to https://foo.library.com, the request will fail with ablocked:csp error.
To get around this limitation there are several options to consider:
- Fork the library (to use mapped urls)
- Utilize a post-install utility such as patch-package
- Use our Embedded App SDK’s patchUrlMappingsAPI
patchUrlMappings API, as it will allow a smooth transition from the non-sandboxed dev environment to the production environment.
This method call takes an array of “mappings” which will transform any external network requests to the mappings you’ve defined.
See the example below:
- In this example, imagine you have a third-party library which makes an HTTP request to foo.com
- In the developer portal, create a mapping like this: /foo->foo.com
- Then in your code, when initializing the SDK, you will make a function call.
Note: 
patchUrlMappings is modifying your browser’s fetch, WebSocket, and XMLHttpRequest.prototype.open global variables. Depending on the library, you may see side effects from using this helper function. It should be used only when necessary.Security Considerations
Trusting Client Data
Do not trust data coming from the Discord client as truth. It’s fine to use this data in your application locally, but assume any data coming from the Discord Client could be falsified. That includes data about the current user, their nitro status, their current channel, etc. If you need this information in a trusted manner, contact Discord API directly from your application’s server, with the user token you received from completing the OAuth2 flow. Furthermore, data coming from the Discord client is not sanitized beforehand. Things like usernames and channel names are arbitrary user input. Make sure to sanitize these strings or use.textContent (for example) to display them safely in your UI.
Using Cookies
To set a cookie for your activity to use in network requests through the proxy, make sure the cookie’s domain matches your app’s full{clientId}.discordsays.com domain. You will also need to explicitly set SameSite=None Partitioned on the cookie. SameSite=None is needed as browsers refuse to store or send cookies with higher restriction levels for any navigation within an iframe. Partitioned then limits the use of that cookie to only Discord’s iframes.
Rest assured: other activities will not be able to make requests with your activity’s cookie, thanks to the Content Security Policy (CSP) limiting requests only to your own app’s proxy.