MathanLab

மதன் ஆய்வகம் (Mathan's lab) Rack 01 · Chennai, IN

1 of 9 projects online

Built

Unit kit · v1

Unit kit

What a project needs to join the lab as its own subdomain. The kit is versioned: v1 stays as it is once published, and breaking changes go to v2.

1. Add the lab bar

One line in the unit's HTML puts the lab bar at the top of every page: a link back to the lab, the unit's name and status, a notice on demos, and a switcher to the other units.

<script src="https://mathanlab.com/kit/v1/lab-bar.js" defer></script>

The bar finds its unit from the host name. It sets no cookies, uses no storage and makes no network requests. Its styles stay inside its own Shadow DOM. The unit's CSP must allow script-src https://mathanlab.com.

<!-- Place the bar yourself instead of at the top of <body> -->
<script src="https://mathanlab.com/kit/v1/lab-bar.js" defer data-mount="manual"></script>
<mathanlab-bar></mathanlab-bar>

<!-- Testing on localhost: tell the bar which unit it is -->
<mathanlab-bar unit="eventhorizon.mathanlab.com"></mathanlab-bar>

2. Serve the ping file

Copy lab-ping.svg to the unit's web root. The lab loads https://<unit>/lab-ping.svg as an image to light the unit's NET light. Do not send Cross-Origin-Resource-Policy: same-origin for it; same-site is fine.

3. Security baseline

  • HTTPS only. The lab sends HSTS with includeSubDomains, so a unit without a certificate breaks.
  • Send the headers below, tightened for what the unit actually loads.
  • Cookies are host-only with the __Host- prefix. Never set Domain=.mathanlab.com: one compromised demo could then plant cookies on every other unit.
  • No shared login across units, no secrets in client bundles, and destructive actions turned off in demos.
  • Demos run on synthetic data only. A demo that keeps state resets on a schedule; any shared demo login is printed on the page.
# .htaccess for a static unit on Hostinger (LiteSpeed / Apache)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
  Header always set Content-Security-Policy "default-src 'self'; script-src 'self' https://mathanlab.com; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests"
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()"
  Header always set Cross-Origin-Opener-Policy "same-origin"
</IfModule>
Set-Cookie: __Host-session=…; Path=/; Secure; HttpOnly; SameSite=Lax

4. Checklist

  1. Registry entry added with status building.
  2. Subdomain website created on the host, with its certificate issued.
  3. Unit deployed with the lab bar, the ping file and the headers in place.
  4. Registry status set to demo or live; the lab rebuilt and redeployed.
  5. The unit's NET light comes on, and a header check passes.

Retiring a unit

Set its status to archived first, then delete the website and its DNS record together. A DNS record left pointing at nothing is a subdomain-takeover risk. The service sheet stays in the lab.

Machine-readable list of units: /registry.json.