List the websites whose pages can upload with your public key, so other sites can't put your key in their pages.
Your public key is meant to be in your web pages, so anyone can copy it. Without allowed origins, any other website could put it in its own pages and upload to your app from its visitors' browsers, using your storage.
When you list your sites, every request made with the public key from a page on any other site is refused with
403 origin_not_allowedOriginIn the dashboard, open the app's Settings and find Allowed origins (the API keys page links to it). Add one site per line and save. Or set it from your server with the private key, through
PATCH /app/settings// needs the private key. Pages on other sites can no longer upload with your public key.
await fileboy.setAllowedOrigins(["https://example.com", "https://*.example.com", "http://localhost:*"])
await fileboy.getAllowedOrigins()
// { allowedOrigins: ["https://example.com", ...], blockRequestsWithoutOrigin: false }
await fileboy.setAllowedOrigins([]) // any site again# needs the private key. Pages on other sites can no longer upload with your public key.
fileboy.update_allowed_origins(["https://example.com", "https://*.example.com", "http://localhost:*"])
fileboy.fetch_allowed_origins
# => { "allowedOrigins" => ["https://example.com", ...], "blockRequestsWithoutOrigin" => false }
fileboy.update_allowed_origins([]) # any site again# needs the private key. Pages on other sites can no longer upload with your public key.
client.set_allowed_origins(["https://example.com", "https://*.example.com", "http://localhost:*"])
client.get_allowed_origins()
# {"allowedOrigins": ["https://example.com", ...], "blockRequestsWithoutOrigin": False}
client.set_allowed_origins([]) # any site again// needs the private key. Pages on other sites can no longer upload with your public key.
$fileboy->setAllowedOrigins(['https://example.com', 'https://*.example.com', 'http://localhost:*']);
$fileboy->getAllowedOrigins();
// ['allowedOrigins' => ['https://example.com', ...], 'blockRequestsWithoutOrigin' => false]
$fileboy->setAllowedOrigins([]); // any site againcurl -X PATCH https://api.fileboy.io/app/settings \
-H "Authorization: token YOUR_SIGNED_TOKEN" \
-H "Content-Type: application/json" \
-d '{"allowedOrigins": ["https://example.com", "https://*.example.com"]}'The answer, and
GET /app/settings1 2 3 4 5 6 7 8 9{ "data": { "requireSignedReads": false, "stripLocationOnUpload": false, "playerBranding": {}, "allowedOrigins": ["https://example.com", "https://*.example.com", "http://localhost:*"], "blockRequestsWithoutOrigin": false } }
Send
[]null400 validation_errorAdd your local development server too (for example
http://localhost:*An origin is a scheme, a host and a port, with no path:
https://example.comhttps://example.comhttp://example.comhttps://www.example.comhttps://*.example.comexample.com*.com*.localhost:*http://127.0.0.1:8080http://[::1]:3000xn--Entries are stored normalised: lowercase, without a default port or a trailing slash, and without duplicates.
| Entry | Allows | Does not allow |
|---|---|---|
| https://example.com | https://www.example.com, http://example.com |
| https://app.example.com, https://pr-12.preview.example.com | https://example.com (list it as well) |
| http://localhost:3000 | http://localhost:5173 |
| http://localhost:5173, http://localhost | http://127.0.0.1:5173 |
| https://example.com:8443 | https://example.com |
| Stored as https://example.com |
Fileboy reads the request's
OriginReferernullEvery request that uses the public key:
POST /files/uploadPOST /videos/uploadPOST /videos/:id/poster/uploadPOST /videos/:id/transcripts/uploadThe check happens before the upload is read. These are never checked:
OPTIONSBrowsers send an
OriginIf nothing uploads with the public key from outside a browser, you can refuse them too: tick Also refuse requests that don't say where they came from in the dashboard, or send
blockRequestsWithoutOrigin: trueA refused request gets a
403origin_not_allowed1 2 3 4 5 6 7 8 9HTTP/1.1 403 Forbidden Access-Control-Allow-Origin: * Cache-Control: no-store Content-Type: application/json { "error": "origin_not_allowed", "message": "This app only accepts its public key from the websites in its allowed origins, and https://other-site.example is not one of them. Add it to the app's allowed origins in its settings, or send the request from your server, signed with your private key." }
If your own site is refused, check the scheme, the www and the port in the message against your list.
Allowed origins stop other websites, not other programs. To make sure only your users can upload, have your server decide:
createAccessToken({ upload: true })Allowed origins still help alongside either: they keep your public key off other sites' pages.