Skip to content

Fix/issue 139 and issue 142 security hardening#186

Closed
olathedev wants to merge 2 commits intoNOVUS-X:mainfrom
olathedev:fix/issue-139-and-issue-142-security-hardening
Closed

Fix/issue 139 and issue 142 security hardening#186
olathedev wants to merge 2 commits intoNOVUS-X:mainfrom
olathedev:fix/issue-139-and-issue-142-security-hardening

Conversation

@olathedev
Copy link
Copy Markdown

Title: fix runtime crashes and harden backend security

closes #142

Body:

Summary

Changes

Issue 139 — Runtime Crashes

  • schemas/user.py: add missing Enum import alongside StrEnum
  • core/config.py: add SOROBAN_NETWORK_PASSPHRASE and BACKEND_SECRET_KEY settings; fix 8-space indentation in Soroban block
  • services/soroban.py: replace module-level SorobanServer() and Keypair.from_secret() calls with lazy helpers (_get_soroban_server, _get_backend_signer) — importing the module without Stellar secrets configured no longer crashes the app

Issue #142 — Security Hardening

  • Rate limiting (slowapi): /auth/login 5/min, /auth/register 3/hr, /auth/refresh 10/min; returns HTTP 429 + Retry-After on breach; adds SlowAPIMiddleware to main.py; adds slowapi to requirements.txt
  • Payment auth guards: POST /payments/release and /payments/refund now require Depends(require_admin); admin user_id is logged on each action
  • Stub endpoints replaced with real DB operations:
    • DELETE /artisans/{id} — deletes from DB, returns 404 if not found
    • PUT /artisans/availability — updates is_available using new AvailabilityUpdate schema (replaces raw dict)
    • GET /artisans/my-portfolio — queries actual Portfolio records for the current artisan
    • POST /artisans/portfolio/add — creates a Portfolio record using new PortfolioItemAdd schema; returns 201

Test plan

  • python -c "from app.schemas.user import RegisterRequest" succeeds
  • python -c "from app.services.soroban import invoke_contract_function" succeeds without Stellar secrets
  • Unauthenticated POST /payments/release and /payments/refund return 401
  • Non-admin calls to those endpoints return 403
  • DELETE /artisans/{id} removes record (subsequent GET returns 404)
  • PUT /artisans/availability persists is_available change to DB
  • Portfolio add/read endpoints create and return real records
  • 6+ rapid login attempts trigger HTTP 429
  • All existing pytest tests pass (pytest)
  • New tests pass: test_rate_limiting.py, test_payment_auth_guards.py, test_stub_endpoints.py

olathedev and others added 2 commits March 25, 2026 22:04
… security

Resolves NOVUS-X#139 — Fix Runtime Crashes From Latest Merge:
- schemas/user.py: add missing `Enum` import alongside `StrEnum`
- core/config.py: add `SOROBAN_NETWORK_PASSPHRASE` and `BACKEND_SECRET_KEY`
  settings; fix 8-space indentation in Soroban config block
- services/soroban.py: replace module-level `SorobanServer()` and
  `Keypair.from_secret()` calls with lazy-initialised helpers
  (`_get_soroban_server`, `_get_backend_signer`) so importing the module
  without Stellar secrets configured no longer crashes the app

Resolves NOVUS-X#142 — Backend Security Hardening:
- Rate limiting (slowapi): `/auth/login` 5/min, `/auth/register` 3/hr,
  `/auth/refresh` 10/min; HTTP 429 + Retry-After on breach; adds SlowAPI
  middleware to main.py; adds slowapi to requirements.txt
- Payment auth guards: `POST /payments/release` and `/payments/refund` now
  require `require_admin`; logs admin user_id on each action
- Stub endpoints replaced with real DB operations:
  - `DELETE /artisans/{id}`: deletes from DB, returns 404 if not found
  - `PUT /artisans/availability`: updates `is_available` via `AvailabilityUpdate`
    schema (replaces raw `dict`)
  - `GET /artisans/my-portfolio`: queries Portfolio records for current artisan
  - `POST /artisans/portfolio/add`: creates Portfolio record via
    `PortfolioItemAdd` schema; returns 201

Adds new test files per acceptance criteria:
- test_rate_limiting.py
- test_payment_auth_guards.py
- test_stub_endpoints.py

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gabito1451
Copy link
Copy Markdown
Collaborator

please look in to ci @olathedev also resolve conflicts

@gabito1451 gabito1451 closed this Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ISSUE-04 · 🟠 HIGH — Backend Security Hardening (Rate Limiting + Auth Guards + Stub Endpoints)

2 participants