Skip to content

[1.0.1][Security] Prevent destructive DB schema drop on startup (go-api) #94

@0sm0s1z

Description

@0sm0s1z

Summary

go-api currently executes a destructive schema reset path during initialization, which can wipe data on service restart.

Why this matters

This is a production data-loss risk. Any startup path that can drop tables by default is unacceptable for production readiness.

Evidence

In minor-projects/go-api/sirius/postgres/connection.go, initializeSchema() calls dropTablesInOrder() before migration.

Current behavior

  • startup -> initializeSchema()
  • initializeSchema() -> dropTablesInOrder()
  • then migrations run

Expected behavior

  • destructive schema reset is disabled by default
  • production start never drops tables automatically
  • reset path requires explicit opt-in flag for dev/test only

Proposed fix

  1. Introduce explicit env gate (example: DB_RESET_SCHEMA=true).
  2. Default to safe (false) when unset.
  3. Guard dropTablesInOrder() behind that flag.
  4. Add startup log warning when reset mode is enabled.
  5. Add tests for both safe and reset modes.
  6. Ensure production compose/deploy configs never set reset flag.

Acceptance criteria

  • Service startup does not drop tables when reset flag is unset.
  • Reset only occurs when explicit flag is true.
  • Unit/integration test covers safe and reset startup modes.
  • Production deployment docs/config explicitly state reset flag must remain disabled.

Release target

1.0.1 security hardening

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions