| 1 | # nginx for the level 2 extension sandbox of Elffuss Code. A TEMPLATE: replace |
| 2 | # SANDBOX_DOMAIN (a registrable domain used only for this) and SANDBOX_DIR |
| 3 | # (the folder deploy-sandbox.sh fills), then generate the two header snippets: |
| 4 | # |
| 5 | # node sandbox/x2/headers.mjs --nginx --sandbox https://x2.SANDBOX_DOMAIN |
| 6 | # |
| 7 | # and save them as /etc/nginx/snippets/x2-sandbox.conf and x2-exthost.conf. |
| 8 | # Order (README, "Extensions that run code"): main's deploy.sh protecting |
| 9 | # vendor/x2/ first (deploy-vendor.sh refuses until it does), DNS and |
| 10 | # certificate for a domain that is not a subdomain of Code's, this vhost, |
| 11 | # nginx -t and reload, deploy-sandbox.sh, deploy-vendor.sh, then deploy.sh |
| 12 | # with web/js/ext2/config.js naming the sandbox. Until that last step Code |
| 13 | # says "not available on this site" and nothing changes for anyone. |
| 14 | |
| 15 | server { |
| 16 | listen 443 ssl http2; |
| 17 | server_name x2.SANDBOX_DOMAIN; |
| 18 | ssl_certificate /etc/letsencrypt/live/x2.SANDBOX_DOMAIN/fullchain.pem; |
| 19 | ssl_certificate_key /etc/letsencrypt/live/x2.SANDBOX_DOMAIN/privkey.pem; |
| 20 | root /var/www/SANDBOX_DIR; |
| 21 | access_log off; # the sandbox keeps no log of who loaded it |
| 22 | autoindex off; |
| 23 | server_tokens off; |
| 24 | |
| 25 | # the sandbox document: only with no query string at all |
| 26 | location = /x2/v1/sandbox.html { |
| 27 | if ($args != "") { return 404; } |
| 28 | include snippets/x2-sandbox.conf; |
| 29 | try_files $uri =404; |
| 30 | } |
| 31 | |
| 32 | # the extension-host document: only the exact query the library builds |
| 33 | # (escape the dots of the domain in the pattern: x2\.example\.org) |
| 34 | location = /x2/v1/exthost-iframe.html { |
| 35 | if ($args !~ "^parentOrigin=https%3A%2F%2Fx2\.SANDBOX_DOMAIN_ESCAPED&vscodeWebWorkerExtHostId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") { return 404; } |
| 36 | include snippets/x2-exthost.conf; |
| 37 | try_files $uri =404; |
| 38 | } |
| 39 | |
| 40 | # nothing else exists on this host |
| 41 | location / { return 404; } |
| 42 | } |
| 43 | |
| 44 | server { |
| 45 | listen 80; |
| 46 | server_name x2.SANDBOX_DOMAIN; |
| 47 | access_log off; |
| 48 | return 301 https://$host$request_uri; |
| 49 | } |
| 50 | |
| 51 | # In the server block of Code (code.elffuss.com), for the verified vendor |
| 52 | # bundle that deploy-vendor.sh uploads (never compressed again on the way, so |
| 53 | # the browser checks the exact bytes of the manifest): |
| 54 | # |
| 55 | # location ^~ /vendor/x2/ { |
| 56 | # default_type application/octet-stream; |
| 57 | # gzip off; |
| 58 | # add_header Cache-Control "public, max-age=31536000, immutable"; |
| 59 | # add_header X-Content-Type-Options nosniff always; |
| 60 | # } |
| 61 | # |
| 62 | # No `always` on Cache-Control: nginx then adds it only to successful |
| 63 | # responses. With `always`, a 404 for a build that is not there yet would be |
| 64 | # cached as immutable for a year, and since the buildId is a content hash, |
| 65 | # uploading the same bytes later would not help those browsers. |
| 66 | # |
| 67 | # Code's host must never serve /x2/ (the sandbox documents live outside web/, |
| 68 | # so deploy.sh never uploads them). |