Restricting CORS Origins
Purpose: Limit which websites a browser may call the StorageLink API from, for example when a security scanner flags the Access-Control-Allow-Origin header
Property: features.api.cors-allowed-origin-pattern, default * (any origin)
Value: A comma-separated list of exact origins such as https://files.example.com, or wildcard patterns such as https://*.example.com. Include the port when it isn't 443 or 80
VM: Add the line to /opt/swiftgw/application.properties, then run sudo systemctl restart swiftgateway
Containers: Set FEATURES_API_CORS_ALLOWED_ORIGIN_PATTERN on the backend container and recreate it
Verify: curl -s -D - -o /dev/null -H 'Origin: https://evil.example' https://<your-host>/backend/actuator/health returns 403 instead of echoing the origin
Product: StorageLink by Thorn Technologies — cloud storage gateway for secure file sharing
Overview
When a web page on one site calls an API on another site, the browser sends an Origin header naming the page's site. The API's Cross-Origin Resource Sharing (CORS) response tells the browser whether to allow the call.
By default, StorageLink allows any origin and echoes it back in the Access-Control-Allow-Origin response header. This is deliberate: customers reach StorageLink through dynamic IP addresses, cloud-generated host names and custom domains, and the default works for all of them.
The default is low-risk. StorageLink sends access tokens in the Authorization header rather than in cookies, and never sends Access-Control-Allow-Credentials, so a page on another site can't act on a signed-in user's session. Some security scanners still flag the echoed origin. If yours does, or your security policy requires an allow-list, set the property in this article.
How the allow-list works
The property takes a comma-separated list. Each entry is an origin: the scheme, the host name, and the port when it isn't the default (443 for https, 80 for http).
| Entry | Allows | Doesn't allow |
|---|---|---|
https://files.example.com | https://files.example.com | http://files.example.com, https://files.example.com:8443 |
https://files.example.com:8443 | https://files.example.com:8443 | https://files.example.com |
https://*.example.com | https://files.example.com, https://a.b.example.com | https://example.com |
*in the host name matches any subdomain, at any depth. It doesn't match the domain itself, so listhttps://example.comseparately if you need it.- The scheme and the port must match exactly.
- Spaces after the commas are ignored.
StorageLink rejects a call from another site whose origin isn't on the list with 403 and the body Invalid CORS request. Requests that carry no Origin header, such as curl commands and API scripts, are not affected.
Which addresses to include
StorageLink's own web pages, the web admin and the web file UI, reach the backend through StorageLink's web server. The backend treats those calls as coming from the same site, so they keep working even when the address users browse to isn't in the list. We tested this with a list that left out the instance's own address: on a VM, signing in (including single sign-on), browsing, uploading, downloading and deleting files all kept working, and on the containers, signing in did.
The exception is a proxy or load balancer in front of StorageLink that changes the Host header, for example an Azure Application Gateway set to override the host name with the backend's address. The backend then sees the browser's calls as coming from another site, and rejects them with 403 unless that address is on the list. To be safe in any setup, include every address your users browse to, such as your custom domain and your load balancer's DNS name. Listing your own addresses doesn't weaken the restriction.
Set the allow-list on a VM
SSH into the StorageLink VM
Edit the application properties file:
sudo nano /opt/swiftgw/application.propertiesAdd the property with your origins on one line, for example:
features.api.cors-allowed-origin-pattern=https://files.example.com,https://*.example.comSave the file, then restart StorageLink:
sudo systemctl restart swiftgateway
For help editing the file from the terminal, see Editing Files on Linux (nano & vi).
Set the allow-list on containers
Set the FEATURES_API_CORS_ALLOWED_ORIGIN_PATTERN environment variable on the backend container. The UI container doesn't use it. See the Container Deployment Reference for the other backend variables.
Docker Compose
Add the variable to the backend service's environment section in docker-compose.yml:
backend:
environment:
FEATURES_API_CORS_ALLOWED_ORIGIN_PATTERN: "https://files.example.com,https://*.example.com"
Then recreate the backend container:
docker compose up -d
Kubernetes manifests
Add the variable to the storagelink-backend-config ConfigMap in k8s/configmap.yaml:
data:
FEATURES_API_CORS_ALLOWED_ORIGIN_PATTERN: "https://files.example.com,https://*.example.com"
Apply the change, then restart the backend so the pods read the new value. Pods don't pick up ConfigMap changes on their own:
kubectl apply -k k8s/
kubectl rollout restart deployment/backend -n storagelink
Helm chart
Chart 0.3.0 has no value for this variable, so set it on the backend Deployment. Kubernetes restarts the backend pods automatically:
kubectl set env deployment/storagelink-backend -n storagelink \
FEATURES_API_CORS_ALLOWED_ORIGIN_PATTERN='https://files.example.com,https://*.example.com'
The Deployment is named <release-name>-backend, so storagelink-backend for a release named storagelink. After a helm upgrade or a reinstall, check that the variable is still set, and run the command again if it isn't:
kubectl set env deployment/storagelink-backend -n storagelink --list | grep CORS
Verify the change
From your workstation, send a request with an origin that isn't on your list. Replace <your-host> with the address you use for StorageLink:
curl -s -D - -o /dev/null -H 'Origin: https://evil.example' https://<your-host>/backend/actuator/health
- Before the change, the response is
200and echoes the origin:access-control-allow-origin: https://evil.example - After the change, the response is
403, with noaccess-control-allow-originheader
Run the command again with one of your allowed origins in place of https://evil.example. That request returns 200 and echoes the allowed origin.
Then sign in to the web admin from your browser, and check that you can browse, upload and download files.
Return to the default
To allow any origin again, remove the features.api.cors-allowed-origin-pattern line from /opt/swiftgw/application.properties and restart StorageLink. On containers, remove the FEATURES_API_CORS_ALLOWED_ORIGIN_PATTERN variable and recreate or restart the backend.
