Skip to content

7.1.0

Latest

Choose a tag to compare

@nadeko0 nadeko0 released this 01 Dec 22:45

Added

  • confirmation_token (ctoken_...) optional request field on POST /api/v1/orders/{order_id}/pay as an alternative to payment_method_token (pm_...): clients must send exactly one of the two (422 otherwise), both are included in the idempotency request fingerprint, and the in-process mock provider accepts ctoken_card_* equivalents of its pm_card_* test cards.
  • Every consent record (registration, consent changes, marketing changes in the profile) carries privacy_policy_version, the version of the privacy policy in force at that moment, so that which text a person agreed to can be shown (GDPR Art. 7(1)). It is in consent_history of GET /api/v1/legal/consent-status; records written before 7.1.0 have it as null.
  • Security audit events on the app.audit logger: failed logins (with the reason, server side only), refresh token replays, admin requests that change something and admin routes refused to non-admins, password resets, logouts and personal data export and deletion requests. Ids only, no emails or tokens; see docs/OPERATIONS.md.
  • The 409 insufficient-stock response of POST /api/v1/cart/items and PUT /api/v1/cart/items/{product_id} now carries available (units in stock) and requested (the requested line total).
  • rate_limit.exceeded audit event (WARNING) for every request refused with 429 by the rate limiter, with the operation (method and route template) and the limit that applied; nothing about the caller.
  • JSON log lines carry stack_info when a record was logged with stack_info=True.
  • BCRYPT_WAIT_TIMEOUT_SECONDS (default 10): a request that waits that long for a password hashing slot is answered 503 service-overloaded with Retry-After: 5 instead of queueing without limit. Affects register, login, password reset confirmation and account deletion under a flood of password checks.
  • Stripe Radar early fraud warnings (radar.early_fraud_warning.created and radar.early_fraud_warning.updated) are recorded per payment and shown to admins: GET /api/v1/orders/{order_id}/payments lists them under each payment's fraud_warnings, and GET /api/v1/admin/payments has a has_fraud_warning field and a has_fraud_warning=true|false filter. Nothing changes automatically: the order, its payment status and its refunds are untouched and no refund is issued. The webhook endpoint must be subscribed to the two new event types.

Upgrade notes

  • BCRYPT_ROUNDS above 15 is refused at startup (it was accepted up to bcrypt's own 31). Each step doubles the cost of every login: 16 is about 5 s a hash. A deployment with a value above 15 must lower it.
  • The HTTP API is unchanged. Operators who traced with OTEL_* and an image built with INSTALL_TELEMETRY=true get no spans after the upgrade, and the build argument is ignored; remove both from the deployment.

Removed

  • ESSENTIAL_COOKIES and COOKIE_CONSENT_EXPIRE_DAYS settings: the application sets only the guest cart cookie (not session, csrf_token or a consent cookie).
  • The RELOAD setting. Nothing read it: uvicorn's auto-reload follows DEBUG (on in development). Setting it has no effect, as before.
  • OpenTelemetry tracing: app/core/telemetry.py, the telemetry extra, the INSTALL_TELEMETRY build argument of the image and the OpenTelemetry SDK, exporter and instrumentation packages (with protobuf and wrapt, which only they needed). OTEL_* variables are no longer read. opentelemetry-api stays in the lock as a dependency of FastAPI itself; without an SDK it does nothing. Logs keep request_id and the trace_id of an incoming traceparent, in the API and in Celery tasks. A single API and worker are debugged by these ids and the slow statement log; distributed tracing pays off across several services, which this project does not have.
  • RedisService.update_cart/delete_cart and AsyncRedisService.update_cart/delete_cart, which nothing in the application called. Internal only; no API change.

Changed

  • The order email sent when an order is created now says the order was received and is awaiting payment (Order #<id> received - awaiting payment); a successful payment sends its own "payment received, order confirmed" email instead of the generic order-status-update email.
  • POST /api/v1/orders/{order_id}/pay now creates and confirms a PaymentIntent in a single Stripe PaymentIntent.create(..., confirm=True) call using the attempt's provider idempotency key (no separate :confirm call or key for new attempts). Legacy unknown attempts created before 7.1.0 that already hold an unconfirmed PaymentIntent id still complete via confirm with the :confirm key on retry.
  • Legal documents (privacy-policy.md, terms-of-service.md, cookie-policy.md) moved from inline strings in app/api/v1/legal.py to versioned Markdown files under app/legal/ (version 1.1, effective 2026-11-28), overridable via LEGAL_DOCS_DIR, and corrected outdated or inaccurate statements (removed the closed EU Online Dispute Resolution platform reference, fixed Directive 2011/83/EU Art. 13(1) refund timing and the account age wording in terms, added recipients, GDPR Chapter V transfer safeguards and Art. 18 restriction right in the privacy policy, and aligned the cookie policy with the guest cart cookie only).
  • Privacy policy 1.2 (effective 2026-12-01) adds the GDPR Art. 13(2)(e) statutory/contractual requirement and the consequences of not providing data, the Art. 13(2)(f) statement that no automated decision-making or profiling with legal effect takes place, a table tying each purpose to its legal basis, and separate retention for account data and accounting records.
  • Email bodies are rendered from Jinja2 HTML templates under app/templates/email/ with autoescape=True and StrictUndefined via app/services/email/templates.py (adding jinja2 3.1.6), replacing f-strings and manual html.escape calls in app/services/email/messages.py.
  • Security headers: tighten Permissions-Policy to the OWASP Secure Headers Project baseline (headers_add.json, 2026-11-23) and add base-uri 'none'; form-action 'none' to the API Content-Security-Policy (base-uri 'self'; form-action 'self' on docs pages).
  • Structured logging: uvicorn's own server and error lines (UVICORN_LOG_CONFIG passed to uvicorn.run) are written as one-line JSON to stdout, and JSONFormatter keeps non-ASCII characters unescaped (ensure_ascii=False).
  • The application is built by app.main.create_app() (the module still exposes app = create_app(), so uvicorn app.main:app is unchanged), and logging is configured when the application starts, in its lifespan, not when app.main is imported. A server started with --lifespan off therefore keeps Python's default logging.
  • A stored cart that cannot be read (corrupt, or written in an incompatible format) is no longer lost: the next cart change keeps the old raw value under <cart key>:unreadable with the cart's TTL and logs a WARNING (an account cart by its account id, a guest cart without its id). It used to be replaced by an empty cart and overwritten.
  • PostgreSQL in Compose logs statements of 500 ms or more with their duration and SQL text, without bound values (log_min_duration_statement=500ms, log_parameter_max_length=0); see docs/OPERATIONS.md.
  • Images: uv 0.13.9 in the app image (was 0.13.6); the PostgreSQL 18.6 and Redis 8.8 (8.8.4) base images on their current digests (rebuilt 2026-11-11 and 2026-11-12).
  • CI: uv 0.13.9, astral-sh/setup-uv v10.4.0, Trivy 0.76.2, the service images on the new digests. The log is shorter: quiet uv sync and uv export, no list of the expected skips in the test job, coverage tables only for files below 100%, one Trivy database download per run instead of three, without a progress bar or a table of clean packages, no build record artifact, and alembic upgrade head in the test setup prints only when it fails. The run page shows the coverage table (files below 100%), and the test job lists its tests slower than one second.
  • CI docker-build: after the Trivy scan, start docker-compose.yml (db, redis, migrate, api) in production mode (.env.example with secrets generated for the run, the Stripe provider and an https frontend, so the deployment startup checks run too) and probe /livez and /readyz.

Fixed

  • The Celery worker and beat start again in the Docker image. kombu's Redis transport imports packaging without declaring it, and the OpenTelemetry packages removed in this release were what installed it, so both services exited at startup with ModuleNotFoundError: No module named 'packaging' (the API was not affected). packaging is now a direct dependency, and the CI compose smoke test starts the worker and beat and fails if either is restarted.
  • POST /api/v1/orders/{order_id}/refund and POST /api/v1/admin/payments/{payment_id}/refund now record each refund request in refund_attempts before calling Stripe: retries with the same Idempotency-Key resend the exact amount sent first (reusing a key with a different amount answers 409 idempotency-key-in-use without calling Stripe), and retries of an unresolved attempt past 23 hours are refused with 409 payment-attempt-unresolved instead of risking a duplicate refund.
  • Long Idempotency-Key headers (up to the 255-character API limit) no longer exceed Stripe's 255-character limit when prefixed with the flow and order id (or suffixed with :confirm on /pay): _provider_idempotency_key keeps the plain format whenever {kind}-order-{order_id}:{client_key}:confirm fits in 255 characters and otherwise hashes client_key with SHA-256 ({kind}-order-{order_id}:sha256:{digest}).
  • POST /api/v1/orders/{order_id}/pay and POST /api/v1/orders/{order_id}/checkout-session no longer re-send an unresolved (unknown) attempt to Stripe after 23 hours (a margin under Stripe's 24-hour idempotency-key retention), answering 409 payment-attempt-unresolved without Retry-After so a stale retry cannot create a duplicate PaymentIntent or Checkout Session.
  • A stored cart (or cached catalog value) that fails validation is logged without its values: the warning names the model, the field locations and the error types only. It used to include pydantic's input_value, so stored cart contents such as product names reached the logs.
  • Dispute webhook events whose payment_intent is not found locally are retried with exponential backoff (STRIPE_EVENT_MAX_RETRIES) instead of being marked processed, ending in failed with an ERROR log naming the dispute id and payment intent id if retries run out; daily reconciliation (check_payment_reconciliation) also reports local open disputes past their evidence_due_by deadline (dispute_past_due), and resolves the discrepancy once the dispute closes.
  • A BACKEND_CORS_ORIGINS entry with an IPv6 host (for example http://[::1]:3000) is kept as written. It used to get a second pair of brackets (http://[[::1]]:3000), so it never matched the browser's Origin header and CORS was refused for that origin.
  • The data deletion request (POST /api/v1/legal/data-request with "request_type": "deletion") answers with the id of the deletion request again for an account that had requested data exports before. It used to return the id of the last export instead, and both confirmation emails carried that export id.
  • Stripe dispute lifecycle rules: inquiries (warning_needs_response, warning_under_review) hold order fulfillment without blocking refunds (allowing a full refund to close an inquiry without a dispute fee); partial lost disputes count only the disputed amount toward Order.payment_status and shrink the remaining refundable amount instead of marking the whole order refunded; and a Stripe "late win" reversing a lost dispute to won is accepted and recomputes payment_status from the payment ledger without that loss.

Full test campaign: docs/reports/test-campaign-7.1.md