Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Optional in local/preview builds. Production releases require the deployed
# Cloudflare Worker origin and validate it during the Vite build.
VITE_PUSH_API_URL=https://hackertok-push.example-account.workers.dev
24 changes: 21 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,34 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Typecheck
- name: Frontend typecheck
run: npm run typecheck

- name: Generate Worker bindings
run: npm run worker:types

- name: Verify generated Worker bindings are current
run: git diff --exit-code -- worker/worker-configuration.d.ts

- name: Worker typecheck
run: npm run worker:typecheck

- name: Lint
run: npm run lint

- name: Test
- name: Frontend tests
run: npm run test:run

- name: Build
- name: Apply local D1 migrations
run: npm run worker:migrate:local

- name: Worker runtime tests
run: npm run worker:test

- name: Wrangler dry run
run: npm run worker:dry-run

- name: Frontend build
run: npm run build

- name: Install Playwright Browsers
Expand Down
173 changes: 168 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:

concurrency:
group: "pages"
cancel-in-progress: true
cancel-in-progress: false

jobs:
build:
Expand All @@ -30,16 +30,40 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Typecheck
- name: Frontend typecheck
run: npm run typecheck

- name: Generate Worker bindings
run: npm run worker:types

- name: Verify generated Worker bindings are current
run: git diff --exit-code -- worker/worker-configuration.d.ts

- name: Worker typecheck
run: npm run worker:typecheck

- name: Lint
run: npm run lint

- name: Test
- name: Frontend tests
run: npm run test:run

- name: Build
- name: Worker runtime tests
run: npm run worker:test

- name: Wrangler dry run
run: npm run worker:dry-run

- name: Install Playwright browsers
run: npx playwright install --with-deps

- name: Browser tests
run: npm run e2e

- name: Build release artifact
env:
REQUIRE_PUSH_API_URL: '1'
VITE_PUSH_API_URL: ${{ vars.PUSH_API_URL }}
run: npm run build

- name: Setup Pages
Expand All @@ -50,6 +74,145 @@ jobs:
with:
path: './dist'

backend:
if: ${{ github.event.release.prerelease == false }}
runs-on: ubuntu-latest
timeout-minutes: 90
needs: build
environment:
name: push-production
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_D1_DATABASE_ID: ${{ vars.CLOUDFLARE_D1_DATABASE_ID }}
PUSH_API_URL: ${{ vars.PUSH_API_URL }}
VAPID_PUBLIC_KEY: ${{ vars.VAPID_PUBLIC_KEY }}
TURNSTILE_SITE_KEY: ${{ vars.TURNSTILE_SITE_KEY }}
steps:
- name: Checkout release
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.release.tag_name }}

- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '24'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Validate deployment configuration
run: |
for name in CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID CLOUDFLARE_D1_DATABASE_ID PUSH_API_URL VAPID_PUBLIC_KEY TURNSTILE_SITE_KEY; do
if [ -z "${!name}" ]; then
echo "::error::$name is not configured"
exit 1
fi
done
node --input-type=module -e "
const url = new URL(process.env.PUSH_API_URL);
const testSiteKeys = new Set([
'1x00000000000000000000AA',
'2x00000000000000000000AB',
'1x00000000000000000000BB',
'2x00000000000000000000BB',
'3x00000000000000000000FF',
]);
if (url.username || url.password || url.pathname !== '/' || url.search || url.hash) {
throw new Error('PUSH_API_URL must contain only an HTTPS origin');
}
if (url.protocol !== 'https:') {
throw new Error('PUSH_API_URL must use HTTPS');
}
if (testSiteKeys.has(process.env.TURNSTILE_SITE_KEY)) {
throw new Error('TURNSTILE_SITE_KEY must not be a Cloudflare test key');
}
console.log('PUSH_API_URL=' + url.origin);
" >> "$GITHUB_ENV"
echo "RELEASE_VERSION=$(git rev-parse HEAD)" >> "$GITHUB_ENV"

- name: Render provisioned Worker configuration
run: |
node --input-type=module -e "
import fs from 'node:fs';
const path = 'worker/wrangler.jsonc';
const config = JSON.parse(fs.readFileSync(path, 'utf8'));
config.d1_databases[0].database_id = process.env.CLOUDFLARE_D1_DATABASE_ID;
config.vars.VAPID_PUBLIC_KEY = process.env.VAPID_PUBLIC_KEY;
config.vars.TURNSTILE_SITE_KEY = process.env.TURNSTILE_SITE_KEY;
config.vars.ALLOWED_ORIGINS = 'https://hackertok.github.io';
config.vars.RELEASE_VERSION = process.env.RELEASE_VERSION;
fs.writeFileSync(path, JSON.stringify(config, null, 2) + '\n');
"

- name: Apply expand-only D1 migrations
run: npm run worker:migrate:remote

- name: Deploy Worker
run: npm run worker:deploy

- name: Wait for bootstrap readiness
run: |
for attempt in $(seq 1 210); do
headers="$(mktemp)"
if curl --fail --silent \
--dump-header "$headers" \
"$PUSH_API_URL/health/ready" \
--output /dev/null; then
deployed_version="$(
awk 'BEGIN { IGNORECASE=1 } /^x-hackertok-release:/ {
sub(/\r$/, "", $2); print $2
}' "$headers"
)"
if [ "$deployed_version" = "$RELEASE_VERSION" ]; then
rm -f "$headers"
exit 0
fi
fi
rm -f "$headers"
sleep 20
done
echo "::error::Worker did not become ready within 70 minutes"
exit 1

- name: Smoke-test public push configuration
run: |
headers="$(mktemp)"
curl --fail --silent --show-error \
--dump-header "$headers" \
"$PUSH_API_URL/health/ready" \
--output /dev/null
deployed_version="$(
awk 'BEGIN { IGNORECASE=1 } /^x-hackertok-release:/ {
sub(/\r$/, "", $2); print $2
}' "$headers"
)"
if [ "$deployed_version" != "$RELEASE_VERSION" ]; then
echo "::error::Smoke-test URL is not serving the deployed Worker version"
exit 1
fi
curl --fail --silent --show-error \
--header "Origin: https://hackertok.github.io" \
"$PUSH_API_URL/v1/push/config" |
node --input-type=module -e "
let body = '';
for await (const chunk of process.stdin) body += chunk;
const config = JSON.parse(body);
if (
typeof config.enabled !== 'boolean' ||
config.threshold !== 1000 ||
typeof config.keyId !== 'string' ||
config.keyId.length === 0 ||
typeof config.applicationServerKey !== 'string' ||
config.applicationServerKey.length < 80 ||
config.turnstileSiteKey !== process.env.TURNSTILE_SITE_KEY
) {
throw new Error('Invalid push configuration response');
}
"

deploy:
permissions:
pages: write
Expand All @@ -58,7 +221,7 @@ jobs:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
needs: backend
steps:
- name: Deploy to GitHub Pages
id: deployment
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ node_modules
dist
dist-ssr
*.local
.wrangler/
.dev.vars
.dev.vars.*
!.dev.vars.example

# Test coverage output
coverage/
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ npm run dev

```bash
npm run typecheck
npm run worker:typecheck
npm run lint
npm run test:run
npm run worker:test
npm run worker:dry-run
npm run build
```

Expand All @@ -62,6 +65,8 @@ npm run e2e
styling system.
- Avoid adding dependencies unless they solve a clear problem that the current
stack cannot reasonably handle.
- Keep Cloudflare changes under `worker/`, regenerate committed bindings with
`npm run worker:types`, and add D1 changes as forward-only migrations.
- If you touch GitHub Actions, keep actions pinned to full commit SHAs.
- If you render remote HTML or user-generated content, keep the existing
sanitization guarantees intact.
Expand Down
92 changes: 92 additions & 0 deletions PRIVACY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Privacy

HackerTok does not require an account and does not link Web Push enrollment to
a Hacker News identity or profile.

## Data used for story alerts

If you enable 1,000+ point story alerts, HackerTok stores one anonymous
installation record containing:

- A browser push-relay endpoint.
- The browser-provided `p256dh` public key and authentication secret required to
encrypt Web Push messages.
- A one-way hash of a random bearer token stored by that browser.
- A one-way hash of the endpoint, the VAPID key ID, and lifecycle timestamps,
including whether that endpoint has completed an accepted relay delivery.
- Internal story, fan-out, delivery, retry, and coarse relay-status records.

HackerTok does not ask for or store your name, email address, Hacker News
username, contacts, advertising identifiers, or browsing history for alerts.
IP-based rate limiting is handled by Cloudflare's rate-limiter binding; IP
addresses are not written to the HackerTok D1 subscription database.

## Browser push services

Native Web Push necessarily passes encrypted messages through the push service
selected by your browser or operating system, such as services operated by
Google, Mozilla, Microsoft, or Apple. Those providers receive the relay endpoint and
transport metadata under their own privacy terms. Notification payloads are
encrypted for the browser subscription.

Cloudflare runs the Worker, D1 database, and Queues used by this feature.
GitHub Pages hosts the HackerTok frontend.

## Anonymous enrollment verification

When you first enable alerts, HackerTok loads Cloudflare Turnstile and sends its
short-lived response token to the Worker for server-side validation. Cloudflare
processes the browser and network signals needed to assess that request under
its own privacy terms. Most visitors see no additional control; a managed
verification interaction may appear when Cloudflare requires one.

The Turnstile response is single-use, expires after five minutes, and is not
stored in HackerTok's D1 database. Reconciliation of an already known random
bearer token does not run another Turnstile challenge.

## Retention and deletion

- Opt-out, permission revocation observed on a later visit, subscription
expiration, or relay `404/410` immediately scrubs the endpoint and encryption
keys.
- A token-hash tombstone remains for up to 30 days to stop a stale browser
reconciliation request from restoring an opted-out subscription.
- Accepted and terminal delivery records are retained for seven days for
recovery and operational diagnosis.
- Minimal Hacker News story IDs remain indefinitely to prevent duplicate
lifetime alerts. Stored title and score details are scrubbed after 90 days.
- Active subscription data remains until opt-out, browser-reported expiry, or a
terminal relay response.

## Controls

Version 1 uses one transient, explicit opt-in action. It never opens a native
notification prompt on page load or after an unrelated click. Turnstile runs
only as part of that action and stays hidden unless managed verification needs
an interaction.

Browser or operating-system notification settings are the initial opt-out
surface. When you later open HackerTok, it reconciles permission and
subscription state and sends a token-only deletion request where needed.
HackerTok intentionally defers a unified notifications/theme settings menu to a
future version.

The random bearer token, subscription fingerprint, pending deletion markers,
and push configuration are stored together in browser IndexedDB so pages and
the service worker can reconcile browser endpoint rotation safely. Tabs use
same-origin browser coordination only; it does not send additional data to a
third party. Other local HackerTok preferences remain in browser storage.
Clearing site data removes these local values; the browser push subscription or
notification permission may also need to be removed in browser settings.

## Logging

HackerTok application logs must not contain raw bearer tokens, authorization
headers, relay endpoints, encryption keys, or subscription request bodies.
Operational logs use public Hacker News story IDs, internal ledger IDs, and
coarse result classes.

## Contact

For privacy or security concerns, use the private reporting process in
[SECURITY.md](SECURITY.md).
Loading
Loading