Web apps, CORS and CSP
This page is for developers who build an app that runs in a browser: a progressive web app, a single-page app, or a JavaScript front end on its own domain. Browsers enforce rules that native apps do not meet, and this page explains how they apply to Exponential.
Contents
Same origin or another origin
| Setup | What the browser allows |
|---|---|
| The app is served from the same scheme, host and port as the Exponential site (for example a design or siteaccess of the site, like the expservices sample portals) | every API call, with the site's session cookie |
The app is on another host (app.example.com calling www.example.com) | only what CORS headers from the server allow |
The sample portals of expservices (/portaljq/, /portalreact/ and others) are browser front ends built only on
the remote services and served by the site itself, so they need no CORS
(Remote services and apps, section 7).
CORS
Neither the REST framework (kernel/private/rest/), ezjscore nor expservices sends Access-Control-Allow-* headers,
and no setting in the shipped INI files adds them. A browser app on another origin therefore cannot call the APIs
directly. The options:
- Serve the app from the same origin, as a design of the site or under a path the web server maps to the app's files.
- Put a back end on the app's origin that calls Exponential server-to-server (A back end for your app). This also keeps tokens out of the browser.
- Add CORS headers at the web server or a proxy, for the API paths only, with an explicit list of allowed origins
(never
*together with credentials), and answer theOPTIONSpreflight there. This is hosting work; review it as a security change (Security hardening).
Native apps (iOS, Android, desktop) and React Native's networking are not subject to CORS.
Content Security Policy
Exponential sends a Content Security Policy from site.ini [ContentSecurityPolicy]; by default it is report-only on
the administration and off on the sites, and its shipped directives include connect-src 'self'
(Content Security Policy). If your app is served by the site and
the site enforces the policy, calls to other hosts (your back end on another domain, an analytics service) need
connect-src entries, and inline scripts are not allowed: load data the way
Content Security Policy for your code describes.
Signing in from a browser
- Same origin: sign in through the site and use the session cookie. Writes to the remote services then need the
form token: get it from
expsession::tokenand send it asX-CSRF-Tokenand as the fieldezxform_token(Writing through expservices). - Another origin: let the back end on the app's origin hold the credentials; do not keep tokens in
localStorage(Storing secrets on devices).
Service workers
The site's own service worker, /index.js (with /sw.js as its old name), is a navigation cache for site pages: it
keeps only same-origin GET navigations made without a session cookie, and only successful pages
(Offline and repeat visits).
It does not cache API answers for your app. A PWA that needs offline data registers its own worker with its own
scope and its own cache rules, and must not take over the site's scope; agree on scopes with the site team.
Related pages
- Headless Exponential
- The response cache, and getting out of the network's way
- Security for applications
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.