Repository navigation
switching main to local hosting branch - #147
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0acea4fa2b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return | ||
| } | ||
|
|
||
| if blocked, retryAfter := checkLoginRateLimit(context.ClientIP(), request.Username); blocked { |
There was a problem hiding this comment.
Trust the proxy client IP before applying IP lockouts
In the Docker deployment, /auth/login reaches Gin through nginx on the Compose bridge, but main.go trusts only loopback proxies, so context.ClientIP() resolves to nginx's container address for every public user. After 20 failed attempts across any usernames, this shared IP key blocks all users from signing in for five minutes; trust the nginx hop or avoid aggregating this limiter across proxied clients.
Useful? React with 👍 / 👎.
| router.GET("/messages/:username/with/:other", handlers.RequireAuth(), handlers.RequireSameUser(), handlers.GetDirectMessages) | ||
| router.POST("/messages/:username/with/:other", handlers.RequireAuth(), handlers.RequireSameUser(), handlers.CreateDirectMessage) | ||
| router.GET("/messages/:username/stream", handlers.StreamDirectMessages) | ||
| router.GET("/messages/:username/stream", handlers.RequireAuth(), handlers.RequireSameUser(), handlers.StreamDirectMessages) |
There was a problem hiding this comment.
Allow the WebSocket route to authenticate its token protocol
The conversation client sends the JWT in Sec-WebSocket-Protocol, but RequireAuth accepts only an Authorization: Bearer ... header. Since the middleware runs before StreamDirectMessages, its protocol-aware token extraction is never reached and every direct-message stream handshake is rejected with 401. Use middleware that reads the WebSocket protocol or leave authentication to the handler.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| const ws = new WebSocket(wsUrl); | ||
| const ws = new WebSocket(wsUrl, [`devbits.jwt.${token}`]); |
There was a problem hiding this comment.
Negotiate the WebSocket subprotocol the client requests
For browser/web clients, even after the route accepts this token, the constructor requires the server to select a subprotocol. The backend wsUpgrader has no configured subprotocols, so it won't acknowledge devbits.jwt.<token> and the browser fails the handshake; the WHATWG WebSocket standard requires a requested protocol to be acknowledged. Configure the upgrader to select an offered protocol or use another credential transport.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects include a build-blocking TypeScript configuration, JWT exposure in logs, unbounded login-tracking memory growth, and deployment and restore scripts that risk downtime or incomplete data restoration.
20 open issues
Failed-login entries grow without bound · New Request logs still expose query-string tokens · New Combined access logs expose stream tokens · New Certbot failure leaves nginx stopped · New Backend can access the database during restore · New Restore can succeed despite SQL errors · New TypeScript 5.9 rejects ignoreDeprecations 6.0 · New Local-only admin access fails behind Docker nginx · New Admin JWT sent as an invalid X-Admin-Key · New Stale search requests overwrite newer results · New Inspector overlay is not an accessible dialog · New Debounced search can apply stale responses · New Nginx client IP breaks login rate limiting · New WebSocket auth rejects tokens sent via subprotocol · New Proxy locations omit inherited security headers · New Auth rate limits target paths the router does not use · New Password sync mishandles quoted values and database users · New PowerShell deployment ignores native command failures · New WebSocket handshake does not negotiate a subprotocol · New Tunnel origin does not match nginx configuration · New
What changed in this PR
This PR moves DevBits from AWS-oriented deployment to self-hosted Docker Compose and nginx, switches production defaults to devbits.ddns.net, and refreshes the admin console.
Changes:
- Replaces AWS deployment tooling with Compose workflows, certificate management, and updated database scripts.
- Updates mobile configuration, production URLs, WebSocket authentication, and login protection.
- Rebuilds the admin interface and adds hosting, security, and release documentation.
| File | Description |
|---|---|
TODO.md |
Tracks admin-console implementation and testing. |
SECURITY_NEEDS.txt |
Adds Cloudflare Tunnel migration guidance. |
README.md |
Describes Compose/nginx infrastructure instead of AWS. |
INSTRUCTIONS.md |
Updates deployment and mobile publishing commands. |
frontend/tsconfig.json |
Adds a deprecation-suppression setting. |
frontend/services/api.ts |
Switches production API defaults and fallbacks. |
frontend/RELEASE_CHECKLIST.md |
Adds mobile release verification steps. |
frontend/eas.json |
Updates production URLs and removes automatic version increments. |
frontend/app/settings/about.tsx |
Updates the public-site fallback URL. |
frontend/app/conversation/[username].tsx |
Moves WebSocket tokens into subprotocol headers. |
frontend/app/_layout.tsx |
Removes startup configuration logging. |
frontend/app.json |
Removes the static Expo configuration. |
frontend/app.config.js |
Consolidates Expo settings and updates build numbers and domains. |
Bash-Scripts/run-front.sh |
Updates live-backend selection and environment values. |
backend/scripts/update-live.sh |
Replaces native deployment with Compose updates. |
backend/scripts/update-live.ps1 |
Adds Windows deployment and database-password synchronization. |
backend/scripts/restore-deployment-db.sh |
Restores through the database container and restarts services. |
backend/scripts/reset-deployment-db.sh |
Resets deployment data through Compose volumes. |
backend/scripts/README.md |
Rewrites database and deployment operations guidance. |
backend/scripts/issue-letsencrypt-cert.sh |
Adds standalone certificate issuance and renewal. |
backend/scripts/install-aws-systemd-service.sh |
Removes the AWS service installer. |
backend/scripts/deploy-aws-native.sh |
Removes native AWS deployment orchestration. |
backend/scripts/build-backend-linux.sh |
Removes the standalone Linux build helper. |
backend/scripts/backup-deployment-db.sh |
Runs database backups through Compose. |
backend/nginx/nginx.conf |
Adds HTTPS routing, static hosting, logging, and rate limits. |
backend/docs/AWS_TRANSFER_NO_NGINX.md |
Removes the AWS migration runbook. |
backend/docker-compose.yml |
Adds nginx and shared networking; restricts direct API exposure. |
backend/deploy/systemd/devbits-api.service |
Removes the native service template. |
backend/api/main.go |
Updates CORS, request logging, and stream middleware. |
backend/api/internal/handlers/direct_message_routes.go |
Adds subprotocol-token parsing and upgrade responses. |
backend/api/internal/handlers/auth_routes.go |
Adds failed-login tracking and temporary blocking. |
backend/api/admin/static/login.js |
Updates sign-in interactions and password visibility. |
backend/api/admin/static/admin.js |
Replaces the console with React dashboards, search, and inspectors. |
backend/api/admin/static/admin.css |
Adds shared responsive admin styling. |
backend/api/admin/index.html |
Redesigns the admin sign-in page. |
backend/api/admin/console.html |
Loads the React console and browser-side JSX tooling. |
backend/.env.example |
Updates defaults for Docker/nginx hosting. |
.github/workflows/aws.yml |
Removes the AWS ECS deployment workflow. |
.env.example |
Updates the production API example URL. |
.codex |
Listed as changed; no content diff supplied. |
Review effort: Balanced
| state.blockedUntil = now.Add(loginFailureBlockFor) | ||
| } | ||
|
|
||
| loginFailuresByKey[key] = state |
| path := params.Path | ||
| if path == "" && params.Request != nil && params.Request.URL != nil { | ||
| path = params.Request.URL.Path | ||
| } |
| access_log /dev/stdout combined if=$loggable; | ||
| access_log /dev/stdout combined if=$honeypot_loggable; |
| docker compose stop nginx >/dev/null 2>&1 || true | ||
|
|
||
| docker run --rm \ | ||
| -p 80:80 \ | ||
| -v "$BACKEND_DIR/nginx/certs:/etc/letsencrypt" \ | ||
| -v "$BACKEND_DIR/nginx/certs/lib:/var/lib/letsencrypt" \ | ||
| certbot/certbot "${CERTBOT_FLAGS[@]}" | ||
|
|
||
| # Bring nginx back online. | ||
| docker compose up -d nginx >/dev/null |
| psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -c "DROP SCHEMA IF EXISTS public CASCADE;" | ||
| psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -c "CREATE SCHEMA public;" | ||
| psql "$DATABASE_URL" -v ON_ERROR_STOP=1 < "$RESOLVED_BACKUP" | ||
| docker compose exec -T db psql -U "$DB_USER" -d postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='${DB_NAME}' AND pid <> pg_backend_pid();" |
| location = /api/auth/login { | ||
| limit_req zone=auth_limit burst=20 nodelay; | ||
| proxy_pass http://backend_upstream; | ||
| proxy_http_version 1.1; | ||
| proxy_set_header Upgrade $http_upgrade; | ||
| proxy_set_header Connection $connection_upgrade; | ||
| proxy_set_header Host $host; | ||
| proxy_set_header X-Real-IP $remote_addr; | ||
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| proxy_cache off; | ||
| proxy_cache_bypass 1; | ||
| proxy_no_cache 1; | ||
| add_header Cache-Control "no-store" always; | ||
| } | ||
|
|
||
| location = /api/auth/register { |
| if ($envRaw -match "(?m)^POSTGRES_PASSWORD=(.+)$") { | ||
| $dbPass = $Matches[1].Trim() |
| docker compose up -d --build backend nginx | ||
| Write-Host "Backend and nginx services have been updated." -ForegroundColor Green |
| } | ||
|
|
||
| const ws = new WebSocket(wsUrl); | ||
| const ws = new WebSocket(wsUrl, [`devbits.jwt.${token}`]); |
| 5.5) Service Type: HTTP. | ||
| 5.6) URL: localhost:80. |



No description provided.