Secrets and Security · Chapter 3 of 3 · 4 min

Hardening a Small Site

The protections that matter most for a small public website with sign-in, payments and an admin area, and how each one is checked by a test.

Proportionate security

A small site is not a bank, but it still has things worth protecting: visitors' accounts and email addresses, payment records, an admin area, and its own reputation. The goal is to close the doors that attackers try first, and to make each protection something a test checks, so it cannot quietly disappear.

1. Security headers

The server sends standard security headers on every response, set in one place with the helmet library:

Ravi OS's health check reads these headers from live pages and shows whether each one is present, so a change that drops them is noticed.

2. Know the real visitor address

Behind Cloud Run's front end, Express must trust exactly one proxy hop. Too little trust and all visitors share one address and one rate-limit bucket; too much and anyone can fake an address with a header. Tests pin both halves of this setting.

3. Rate limits

Requests are counted per visitor address over fifteen-minute windows, with separate limits for sign-in, the admin area, public forms, payments and the AI mentor. That blunts password guessing, scraping and runaway costs on a paid AI API. The limits live in memory on each instance, which is exact while one instance serves the site and approximate if several do. That limit is written down, not discovered.

4. Sign-in and sessions

5. Private pages stay private

Every admin and dashboard page requires a login, is marked noindex so search engines never list it, and is sent with no-cache headers so a shared computer or proxy does not keep a copy. Requests that change data must also carry a same-site header, which blocks cross-site request forgery. Tests open every private route without a login and expect a refusal.

6. Payments and webhooks

Payment providers report payments to your server with a webhook. Anyone can send a request to that address, so:

Each of those sentences is a test on this site.

7. The database is not a public API

Firestore can be reached directly from browsers if its rules allow. Here, the security rules deny all direct browser access to private collections; only the server, with its own identity, reads and writes them.

8. The container

Non-root user, slim base, no secrets inside, production dependencies only (see Smaller, Safer Images).

9. Dependencies

Most code running on any Node site was written by someone else. Habits:

10. Keep the list honest

Some protections are deliberately postponed: a stricter content-security policy without inline styles, and a shared store for rate limits. They are on the backlog with a reason, not forgotten. A short list of "known gaps, and why they are acceptable for now" is part of good security.

Try it yourself

Pick three items from this chapter that your site lacks a test for. Write one test each, starting with the one that would hurt most if it silently broke: usually private pages or webhooks.