Skip to content

Security Hardening Engine: JWT strategy and WebSocket gateway#25

Open
ChukwuemekaP1 wants to merge 4 commits into
OrbitChainLabs:mainfrom
ChukwuemekaP1:main
Open

Security Hardening Engine: JWT strategy and WebSocket gateway#25
ChukwuemekaP1 wants to merge 4 commits into
OrbitChainLabs:mainfrom
ChukwuemekaP1:main

Conversation

@ChukwuemekaP1

Copy link
Copy Markdown

Security Hardening Engine: Implementation Report

This PR hardens the OrbitChain-API by removing insecure defaults, centralizing configuration, and enforcing strict environment validation for production safety.

Summary of Changes
Eliminated hardcoded fallback secrets across Auth, Users, Milestones, Notifications, Redis, and Stellar services
Fixed critical risk of JWT forgery caused by insecure default JWT_SECRET values
Unified authentication logic across HTTP and WebSocket layers
Introduced fail-fast startup validation for all required environment variables
Centralized configuration using AuthConfigService as the single source of truth
Key Improvements
Fail-fast validation: App now stops immediately if required env vars are missing or invalid
No insecure defaults: All fallback secrets and URLs removed
Consistent auth layer: JWT strategy and gateway now use the same config source
Type-safe config access: All sensitive values managed through a dedicated service
Testing
App fails if JWT_SECRET is missing or too weak
App fails if required services (DATABASE_URL, REDIS_URL, etc.) are missing
App boots only with valid, complete configuration
Deployment Notes

Ensure production environment defines:
JWT_SECRET, DATABASE_URL, REDIS_URL, STELLAR_RPC_URL, STELLAR_NETWORK_PASSPHRASE, NODE_ENV

Application will now refuse to start if configuration is incomplete.

closes #3

@Alqku Alqku left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate the direction, @ChukwuemekaP1 — fail-fast env validation, dropping the hardcoded JWT_SECRET defaults, and centralizing JWT/Stellar/Redis/DB config via AuthConfigService is exactly the hardening we need, and the JWT_SECRET minimum length via class-validator is spot-on. Closes #3 conceptually.

Two things need to land before we can merge this safely:

  1. .env.example is not updated. After this lands, fresh clones will refuse to start because the validated env (JWT, STELLAR_RPC_URL, STELLAR_NETWORK_PASSPHRASE, REDIS_URL, DATABASE_URL, NODE_ENV) has no documented placeholders. Please add a sample block with a 32+ char JWT_SECRET value, etc.

  2. CI and npm run test:e2e have no env injection for the new required vars. Today the e2e config at test/jest-e2e.json does not load any required secrets, so once validation is wired into AppModule, e2e will refuse to boot and CI will go red. Please either:

    • add a .env.test (or a CI step that writes one) with valid values, or
    • thread the required vars through gh-actions secrets for the e2e job.
  3. Minor: please run prisma format and regenerate prisma migrate dev --name <...> so the DeadLetter-adjacent schema (if any) is clean — the schema looks untouched in this diff so this may not apply, but worth confirming on re-review.

Security intent is exactly right and we want this in — just please close the dev/CI gap above and we can merge immediately. Thanks!

@ChukwuemekaP1

Copy link
Copy Markdown
Author

Alrigth @Alqku Will get to implement it that way

@ChukwuemekaP1 ChukwuemekaP1 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just did the implentation rigth here @Alqku |

  • Updated .env.example : Added missing STELLAR_RPC_URL and STELLAR_NETWORK_PASSPHRASE , and updated the JWT_SECRET placeholder to remind users of the 32+ character requirement.
  • Created .env.test for e2e tests : Added all required validated env vars (NODE_ENV, JWT_SECRET, DB_URL, etc.) with test-friendly values.
  • Updated test:e2e script : Added NODE_ENV=test so ConfigModule automatically loads .env.test .
  • Ran prisma format : Cleaned up prisma/schema.prisma (no schema changes needed, just formatted).
  • Added .env.test to .gitignore : To keep local test environment variables out of git.
    Everything you mentioned is addressed

Alqku added a commit that referenced this pull request Jun 19, 2026
…cy lint backlog (#28)

* fix(ci): unblock npm ci by bumping @nestjs/schedule to v5 + tame legacy lint backlog

CI on main was failing every job at the npm ci step due to a peer-dep
conflict introduced by PR #23: it pinned @nestjs/schedule@^4.0.0 which
declares peer @nestjs/common@^8 || ^9 || ^10, while the project is on
@nestjs/common@11.1.24.

Once install worked, a latent 227 pre-existing lint errors surfaced in
the codebase (mostly @typescript-eslint/no-unsafe-* from
recommendedTypeChecked). To get CI back to green quickly without
touching dozens of unrelated source files, demoted the offending rule
family to warn with an explicit FAST-PASS comment, dropped
--max-warnings=0 from the CI lint step, and replaced one empty catch
block with an explanatory comment.

Changes:
- package.json: @nestjs/schedule ^4.0.0 -> ^5.0.0 (peer ^10 || ^11)
- package-lock.json: regenerated via npm install --package-lock-only
- eslint.config.mjs: FAST-PASS demotion of 12 tseslint strict rules
  (no-unsafe-*, no-unused-vars, no-misused-promises, require-await,
  restrict-template-expressions, prefer-as-const, no-floating-promises)
  with explicit do-NOT-introduce-new-violations guidance
- .github/workflows/ci.yml: lint step drops --max-warnings=0
- src/stellar/stellar-event.service.ts: replace empty catch (e) {} after
  this.streamCloseFn() with a one-line explaining comment

Followups (tracked in separate issues):
- Bootstrap .env.example and inject a valid JWT_SECRET in CI/e2e for the
  PR #25 env-validation work to land.
- Track and clean up the 250 lint warnings currently classified as
  warnings; restore --max-warnings=0 once the backlog is gone.

CI locally: lint exit 0 (0 errors), build OK, unit tests pass, prettier
OK, prisma validate OK, npm ci clean.

* fix(ci): surface-latent format, prisma-validate, and e2e import blockers

After the first rerun of PR #28, three more latent CI failures surfaced
now that the install issue is fixed:

- format job: 11 files had been last touched before .prettierrc was
  tightened (singleQuote: true, trailingComma: "all"), so they did not
  match the format check. Run `npx prettier --write` over the working
  tree; .gitattributes already enforces *.ts eol=lf so the normalization
  is a sink state.
- prisma-validate: schema uses `url = env("DATABASE_URL")` and the
  GitHub Actions job did not inject that env var, so the optional job
  failed with P1012 even though prisma validate only parses schema.
  Inject a placeholder URL via `env:` on that step only.
- test-e2e: ts-jest in `test/jest-e2e.json` cannot resolve a `.js`
  extension in relative imports. Dropped the extension on
  `StellarTransactionsService` to match the extensionless convention
  already used everywhere else in the file.

Diff scope relative to PR #28 commit 1:
  M  src/stellar/stellar.module.ts   (.js extension dropped)
  M  .github/workflows/ci.yml         (DATABASE_URL env on prisma step)
  M~ 11 src/ files reformatted by prettier --write (whitespace only)

Local validations: lint exit 0 / 0 errors / 250 warnings, build pass,
unit tests pass, prettier pass, prisma validate pass.

Alqku commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Thanks for the security push 🙌 Direction looks solid but we can\u2019t safely merge a 1k+ line auth-touching PR from a fork with no CI validation (prettier/lint/build/tests didn\u2019t get a chance to run on this branch). Mind pushing onto a feature branch so the CI workflow triggers (or rebasing onto current main), then re-run? We\u2019ll move fast once it\u2019s green ✅

@Alqku

Alqku commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

watching the CI now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants