0.2.46: security hardening (external-fund scope, role guards, forced password rotation, headers)

Pre-release audit fixes:
- External Administrators can only act on investors already in their own funds
  (grant_access, create_statement, set_partner_exited, import match), closing a
  cross-fund account-takeover chain.
- Role and is_active changes are gated: no self-escalation, non-approvers cannot
  mint or alter approver accounts, and the Service Admin is protected.
- must_change_password is enforced server-side, not just in the client.
- Session cookie is Secure with a 12h max-age and SameSite; CSP and standard
  security headers on every response; the app refuses to boot on a known or short
  session secret; uvicorn runs with proxy-headers so login throttling keys on the
  real client IP behind the platform proxy.
- Import preview no longer confirms cross-fund investors; no-store on document
  downloads.
- Adds backend/tests/test_security_hardening.py (15 tests); full suite 76 passing.
- SECURITY-AUDIT.md records the swarm audit, findings, and remediation status.
This commit is contained in:
Jonathan Kirkwood
2026-08-28 09:53:16 -05:00
parent 858bbe10da
commit 3a4b7dfd8b
15 changed files with 795 additions and 31 deletions
+2
View File
@@ -42,6 +42,8 @@ RUN groupadd --gid 10001 appuser \
ENV TEN31_DB_PATH=/data/portal.db
ENV TEN31_DOCS_DIR=/data/documents
ENV TEN31_SESSION_SECRET=change-me
# Served behind the platform's TLS-terminating proxy, so the session cookie is Secure.
ENV TEN31_SESSION_COOKIE_SECURE=true
EXPOSE 8000
+26 -12
View File
@@ -1,16 +1,24 @@
#!/bin/sh
set -e
# Generate session secret if not set or default
if [ "$TEN31_SESSION_SECRET" = "change-me" ]; then
if [ -f /data/.session-secret ]; then
export TEN31_SESSION_SECRET=$(cat /data/.session-secret)
else
export TEN31_SESSION_SECRET=$(python3 -c "import secrets; print(secrets.token_hex(32))")
echo "$TEN31_SESSION_SECRET" > /data/.session-secret
chmod 600 /data/.session-secret
fi
fi
# Generate a session secret unless the operator supplied a real one. Any unset/empty value or a
# known placeholder counts as "not set" — the app also refuses to boot on these (see
# main.lifespan), so the two checks must agree on the full placeholder list.
case "$TEN31_SESSION_SECRET" in
""|change-me|change-me-in-production)
if [ -f /data/.session-secret ]; then
export TEN31_SESSION_SECRET=$(cat /data/.session-secret)
else
export TEN31_SESSION_SECRET=$(python3 -c "import secrets; print(secrets.token_hex(32))")
echo "$TEN31_SESSION_SECRET" > /data/.session-secret
chmod 600 /data/.session-secret
fi
;;
esac
# The platform terminates TLS and reverse-proxies to us, so the session cookie is served over
# HTTPS to the client: mark it Secure. Default on here; overridable for a plain-HTTP setup.
export TEN31_SESSION_COOKIE_SECURE="${TEN31_SESSION_COOKIE_SECURE:-true}"
# Create first approver on first boot if no users exist
if [ ! -f /data/.initialized ]; then
@@ -58,10 +66,16 @@ LOG_LEVEL="${TEN31_LOG_LEVEL:-info}"
# Hand off to the server as an unprivileged user. The platform mounts /data owned by root, so
# (while still root) we take ownership of the data volume first, then drop privileges with
# setpriv — the long-running server process is never root, limiting what a compromise can reach.
# --proxy-headers lets uvicorn read X-Forwarded-For from the platform's reverse proxy so the
# login rate limiter keys on the real client IP, not the single proxy address (otherwise one
# source's failures throttle every user). The container port is only reachable via that proxy,
# so trusting forwarded headers from any upstream is safe here.
if [ "$(id -u)" = "0" ]; then
chown -R 10001:10001 /data
exec setpriv --reuid=10001 --regid=10001 --clear-groups \
uvicorn ten31portal.main:app --host 0.0.0.0 --port 8000 --log-level "$LOG_LEVEL"
uvicorn ten31portal.main:app --host 0.0.0.0 --port 8000 --log-level "$LOG_LEVEL" \
--proxy-headers --forwarded-allow-ips="*"
else
exec uvicorn ten31portal.main:app --host 0.0.0.0 --port 8000 --log-level "$LOG_LEVEL"
exec uvicorn ten31portal.main:app --host 0.0.0.0 --port 8000 --log-level "$LOG_LEVEL" \
--proxy-headers --forwarded-allow-ips="*"
fi
+3 -2
View File
@@ -1,5 +1,6 @@
export { v_0_2_45 as current } from './v_0_2_45'
export { v_0_2_46 as current } from './v_0_2_46'
import { v_0_1_0 } from './v_0_1_0'
import { v_0_2_45 } from './v_0_2_45'
import { v_0_2_40 } from './v_0_2_40'
import { v_0_2_41 } from './v_0_2_41'
import { v_0_2_42 } from './v_0_2_42'
@@ -44,4 +45,4 @@ import { v_0_2_36 } from './v_0_2_36'
import { v_0_2_37 } from './v_0_2_37'
import { v_0_2_38 } from './v_0_2_38'
import { v_0_2_39 } from './v_0_2_39'
export const other = [v_0_1_0, v_0_2_0, v_0_2_1, v_0_2_3, v_0_2_4, v_0_2_5, v_0_2_6, v_0_2_7, v_0_2_8, v_0_2_9, v_0_2_10, v_0_2_11, v_0_2_12, v_0_2_13, v_0_2_14, v_0_2_15, v_0_2_16, v_0_2_17, v_0_2_18, v_0_2_19, v_0_2_20, v_0_2_21, v_0_2_22, v_0_2_23, v_0_2_24, v_0_2_25, v_0_2_26, v_0_2_27, v_0_2_28, v_0_2_29, v_0_2_30, v_0_2_31, v_0_2_32, v_0_2_33, v_0_2_34, v_0_2_35, v_0_2_36, v_0_2_37, v_0_2_38, v_0_2_39, v_0_2_40, v_0_2_41, v_0_2_42, v_0_2_43, v_0_2_44]
export const other = [v_0_1_0, v_0_2_0, v_0_2_1, v_0_2_3, v_0_2_4, v_0_2_5, v_0_2_6, v_0_2_7, v_0_2_8, v_0_2_9, v_0_2_10, v_0_2_11, v_0_2_12, v_0_2_13, v_0_2_14, v_0_2_15, v_0_2_16, v_0_2_17, v_0_2_18, v_0_2_19, v_0_2_20, v_0_2_21, v_0_2_22, v_0_2_23, v_0_2_24, v_0_2_25, v_0_2_26, v_0_2_27, v_0_2_28, v_0_2_29, v_0_2_30, v_0_2_31, v_0_2_32, v_0_2_33, v_0_2_34, v_0_2_35, v_0_2_36, v_0_2_37, v_0_2_38, v_0_2_39, v_0_2_40, v_0_2_41, v_0_2_42, v_0_2_43, v_0_2_44, v_0_2_45]
@@ -0,0 +1,19 @@
import { VersionInfo } from '@start9labs/start-sdk'
export const v_0_2_46 = VersionInfo.of({
version: '0.2.46:0',
releaseNotes: {
en_US:
'Security hardening ahead of the investor release. External Administrators can now only ' +
'act on investors already in their own funds (closing a cross-fund account-takeover path). ' +
'Role and active-status changes are restricted so staff cannot escalate their own ' +
'permissions or alter the Service Admin. The forced first-login password change is now ' +
'enforced by the server, not just the browser. Session cookies are marked Secure with a ' +
'shorter lifetime, standard security headers are set on every response, and login ' +
'throttling now sees the real client address behind the platform proxy.',
},
migrations: {
up: async ({ effects }) => {},
down: async ({ effects }) => {},
},
})