Skip to content

fix(csrf): a form token is bound to the session that rendered it #482

fix(csrf): a form token is bound to the session that rendered it

fix(csrf): a form token is bound to the session that rendered it #482

Workflow file for this run

# Copyright (c) 2026 Code Infinity
# SPDX-License-Identifier: MPL-2.0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Build the base image, prove it actually boots and serves the version it claims,
# and only then publish it.
#
# Why this exists: these base images were never built or booted by any CI. Building
# them by hand on 2026-07-27/28 found real defects that had shipped for months --
# a PHP CMD that silently dropped the bind address (so the container was
# unreachable through `docker run -p`), no framework CLI in the image at all, an
# autoloader failure, a Ruby image that exited 2 on every start because it set
# pre-v3 un-prefixed SWAGGER_* vars the framework now refuses to boot with, and a
# Node image reporting version 0.0.0. Every one is caught by the jobs below.
#
# This is deliberately a SEPARATE workflow from publish.yml. The images may be red
# while they are being fixed, and an image defect must never block the package
# publish to PyPI / Packagist / RubyGems / npm, which works today.
name: Docker image
on:
push:
branches: [v3]
tags: ['[0-9]*.*.*']
pull_request:
branches: [v3]
workflow_dispatch:
# REGISTRY: Docker Hub, not GHCR. This is where these images were already being
# published and, more importantly, where the Dockerfile header and every user's
# `docker pull` already point -- `FROM tina4stack/tina4-python:v3` has no registry
# prefix, so it resolves to docker.io. Publishing to GHCR instead would leave the
# documented pull path serving images that predate every fix in this batch.
#
# The CLI image (ghcr.io/tina4stack/tina4-cli) stays on GHCR: it is published by
# the tina4 repo's own CI and the deploy templates pin it there.
#
# PUBLISHING IS MANUAL, ON PURPOSE (owner decision, 2026-07-30). There is no
# publish job here and no Docker Hub credential in this repo. Images are built
# and pushed from the build host, which already holds the credential, using
# tina4-documentation/scripts/publish-docker-images.sh -- it replicates the boot
# gate below (run the container, require 200 on /health through the PUBLISHED
# port, require it still alive, require /health to report a version MATCHING the
# tag) and then gates the arm64 image pulled back from the published manifest.
#
# WHY NOT IN CI: a Docker Hub push token for the tina4stack namespace can
# OVERWRITE `latest` on every published image -- it is a supply-chain write
# primitive, not just a publish credential. Storing it in four repos would mean
# four copies, readable by every third-party action in each workflow, with four
# places to rotate. If this is ever automated, do it with an org-level secret
# scoped to these repos behind a protected environment with a required reviewer,
# or per-repository scoped Docker Hub tokens -- never one account-wide token
# copied per repo.
#
# What DOES run here on every tag: the boot gate, plus an arm64 cross-build
# check. Both are credential-free, so this workflow can never leak anything.
env:
IMAGE: docker.io/tina4stack/tina4-python
APP_PORT: 7146
jobs:
boot-gate:
name: Image boots, binds 0.0.0.0, and reports its real version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- name: Build image (native arch; arm64 is cross-built below)
run: docker build -t "$IMAGE:ci" .
# `docker image inspect -f '{{.Size}}'` LIES under the containerd snapshotter:
# it reports a compressed size, which is why an image measured at 59 MB there
# occupies 183 MB on disk. `du -sx /` inside the container is the ground truth
# a user actually pays for on their disk.
- name: Report image size (on-disk, not the compressed lie)
run: |
kb=$(docker run --rm --entrypoint sh "$IMAGE:ci" -c 'du -sx / 2>/dev/null | cut -f1')
echo "on-disk size: $(( kb / 1024 )) MB"
- name: Boot the container
# ADR-0079: a production image refuses to boot without a >=32-byte
# TINA4_SECRET (blank/short forges tokens). Provide a throwaway one for
# this verification boot; real deployments set their own. The image binds
# 0.0.0.0 by default, so this still proves the 0.0.0.0 bind below.
run: docker run -d --name gate -e TINA4_SECRET=ci-docker-boot-verification-secret-0123456789 -p 8080:$APP_PORT "$IMAGE:ci"
# Probe /health, NEVER "/". A stock scaffold has an empty src/routes and
# answers 404 at "/", and `curl -fsS` scores a 404 as a failure -- which is
# exactly how an earlier run recorded three healthy containers as dead.
#
# A 200 through a PUBLISHED port proves two things at once: the process
# booted, AND it bound 0.0.0.0. A server on 127.0.0.1 inside a container
# cannot answer through -p, so this is the bind check as well as the
# liveness check.
- name: Require HTTP 200 on /health through the published port
run: |
for i in $(seq 1 45); do
if curl -fsS -m 2 -o /dev/null "http://127.0.0.1:8080/health"; then
echo "served after ${i}s"
exit 0
fi
if [ "$(docker inspect -f '{{.State.Running}}' gate)" != "true" ]; then
echo "::error::container exited before serving a request"
docker logs gate
exit 1
fi
sleep 1
done
echo "::error::no 200 on /health within 45s -- the server either failed to boot or bound 127.0.0.1 instead of 0.0.0.0"
docker logs gate
exit 1
# Serving once is not passing. A container that answers and then dies is broken.
- name: Require the container to still be alive
run: |
if [ "$(docker inspect -f '{{.State.Running}}' gate)" != "true" ]; then
echo "::error::container died after serving; OOMKilled=$(docker inspect -f '{{.State.OOMKilled}}' gate)"
docker logs gate
exit 1
fi
# THE TAG MUST NOT LIE ABOUT THE VERSION.
#
# The image tags mirror the framework release (tina4-python:3.13.92), so a tag is
# a claim about what is inside. Verify it instead of trusting it.
#
# This is not hypothetical. The Node image was about to be published as
# 3.13.92 while serving "version": "0.0.0" -- relocating the framework out of
# /app broke a three-level directory walk in the version resolver, which
# silently fell back to "0.0.0". It built, booted, bound 0.0.0.0 and answered
# 200: every other gate here passed it.
#
# "0.0.0" is called out by name because it is the resolvers' fallback
# sentinel, not because it is an implausible version.
- name: Require the image to report a real version
run: |
# ADR-0078 hides `version` from a production /health, so read it from the
# image's own version resolver instead (still catches the 0.0.0 fallback).
version=$(docker exec gate python -c 'import tina4_python; print(tina4_python.__version__)')
echo "reported version: '$version'"
if [ -z "$version" ]; then
echo "::error::the image reported no version -- an unverifiable image must not be published"
exit 1
fi
if [ "$version" = "0.0.0" ]; then
echo "::error::the version resolver reports 0.0.0 -- it failed to locate the package manifest inside the image"
exit 1
fi
if ! echo "$version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+'; then
echo "::error::reported version '$version' is not a release version"
exit 1
fi
# On a tag build the tag is the claim -- it must match exactly.
if [ "${GITHUB_REF#refs/tags/}" != "$GITHUB_REF" ]; then
tag="${GITHUB_REF#refs/tags/}"
if [ "$version" != "$tag" ]; then
echo "::error::version mismatch -- tag says $tag, the container serves $version. Refusing to publish a tag that misreports its own contents."
exit 1
fi
echo "tag $tag matches the served version"
fi
- name: Container logs (always, for diagnosis)
if: always()
run: docker logs gate 2>&1 | tail -50
- name: Clean up
if: always()
run: docker rm -f gate || true
# Cross-compile arm64 as a BUILD check. Nothing is pushed and nothing is
# loaded (buildx cannot --load a foreign-arch result), so this needs no
# registry credential -- it only proves the Dockerfile is not arch-broken
# (wrong base image, a native module with no arm64 build, a bad binary).
# Without it, an arm64 break would not surface until someone published by
# hand, because the boot gate above runs on the native amd64 runner.
- name: Cross-build arm64 (compile only, no push)
run: |
docker buildx create --use --name ci-arm >/dev/null 2>&1 || docker buildx use ci-arm
docker buildx build --platform linux/arm64 -t "$IMAGE:arm64-check" .