Skip to content

Commit

Permalink
fix: improve cors security
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrasch committed Feb 5, 2025
1 parent 02614b5 commit 7d8453c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ web_extra_exposed_ports:
strictPort = true,
// origin is important, see https://nystudio107.com/docs/vite/#vite-processed-assets
origin: `${process.env.DDEV_PRIMARY_URL}:5173`
// Configure CORS for the dev server (security)
cors: { origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(localhost|\.site)(?::\d+)?$/ },
// Configure CORS securely for the Vite dev server to allow requests
// from *.ddev.site domains, supports additional hostnames (via regex)
cors: { origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/ },
},
```

Expand Down
9 changes: 4 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ export default ({ command }) => ({
},
// adjustments for ddev:
server: {
// respond to all network requests:
// Respond to all network requests
host: '0.0.0.0',
port: port,
strictPort: true,
// origin is important, see https://nystudio107.com/docs/vite/#vite-processed-assets
origin: origin,
// Configure CORS for devserver (security)
cors: {
origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(localhost|\.site)(?::\d+)?$/
},
// Configure CORS securely for the Vite dev server to allow requests
// from *.ddev.site domains, supports additional hostnames (via regex)
cors: { origin: /https?:\/\/([A-Za-z0-9\-\.]+)?(\.ddev\.site)(?::\d+)?$/ },
},
plugins: [
ViteRestart({
Expand Down

0 comments on commit 7d8453c

Please sign in to comment.