Skip to content

@W-21461342 Adding Configurable safety levels#235

Merged
charithaT07 merged 16 commits intomainfrom
W-21461342-Configurable-safety-levels
Mar 17, 2026
Merged

@W-21461342 Adding Configurable safety levels#235
charithaT07 merged 16 commits intomainfrom
W-21461342-Configurable-safety-levels

Conversation

@charithaT07
Copy link
Copy Markdown
Collaborator

@charithaT07 charithaT07 commented Mar 6, 2026

Summary

Brief description of what this PR does.

Summary

Adds configurable safety levels to protect against accidental destructive operations. Safety levels provide HTTP-layer protection via the SFCC_SAFETY_LEVEL environment variable that cannot be bypassed by CLI
flags or config files.

Safety Levels

NONE (default)

  • No restrictions
  • Blocks: Nothing

NO_DELETE

  • Prevent deletions only
  • Blocks: DELETE operations

NO_UPDATE

  • Prevent destructive changes
  • Blocks: DELETE + destructive POST (reset/stop/restart)

READ_ONLY

  • Investigation/audit mode
  • Blocks: All write operations (POST/PUT/PATCH/DELETE)

Usage

Block accidental deletions

export SFCC_SAFETY_LEVEL=NO_DELETE
b2c ods sandbox delete prod-sandbox # ❌ Blocked

Read-only mode for investigation

export SFCC_SAFETY_LEVEL=READ_ONLY
b2c ods sandbox list # ✅ Allowed
b2c mrt push # ❌ Blocked

Why Environment Variables?

Uses process.env exclusively for security:

  • ✅ Cannot be bypassed by CLI flags
  • ✅ Cannot be bypassed by config files
  • ✅ LLMs cannot modify parent shell environment
  • ✅ Immutable at runtime

Changes

  • New safety module with 4 protection levels
  • HTTP middleware that intercepts all API requests
  • 137 unit tests with 99.34% coverage
  • 25 CLI commands updated with safety warnings
  • Documentation with CI/CD examples

Works across all HTTP clients (ODS, MRT, OCAPI, SCAPI, eCDN, SLAS).

Dependencies

No new dependencies.

Testing

How was this tested?

Dependencies

  • No net-new third-party dependencies were added
  • If net-new third-party dependencies were added, rationale/discussion is included and 3pl-approved is set by a maintainer

  • Tests pass (pnpm test)
  • Code is formatted (pnpm run format)

@charithaT07 charithaT07 requested a review from clavery as a code owner March 6, 2026 09:31
Copy link
Copy Markdown
Collaborator

@clavery clavery left a comment

Choose a reason for hiding this comment

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

Good implementation. Few comments on how we document this.

Comment thread docs/guide/ci-cd.md
Comment thread docs/guide/security.md Outdated
Comment thread docs/guide/security.md Outdated
Comment thread packages/b2c-tooling-sdk/src/cli/base-command.ts Outdated
Comment thread packages/b2c-tooling-sdk/src/cli/base-command.ts
@charithaT07 charithaT07 requested a review from clavery March 9, 2026 15:58
Comment thread docs/guide/ci-cd.md Outdated
@clavery
Copy link
Copy Markdown
Collaborator

clavery commented Mar 13, 2026

@charithaT07 is this ready. Still says changes requested. If ready request me again

@charithaT07 charithaT07 requested a review from clavery March 14, 2026 16:54
@charithaT07
Copy link
Copy Markdown
Collaborator Author

charithaT07 commented Mar 14, 2026

@charithaT07 is this ready. Still says changes requested. If ready request me again

Yes, changes are done and ready for review again. Thanks

@clavery
Copy link
Copy Markdown
Collaborator

clavery commented Mar 15, 2026

closes #67

@clavery clavery linked an issue Mar 15, 2026 that may be closed by this pull request
Comment thread packages/b2c-tooling-sdk/src/safety/safety-middleware.ts Outdated
Comment thread packages/b2c-tooling-sdk/src/safety/safety-middleware.ts Outdated
@charithaT07 charithaT07 requested a review from clavery March 16, 2026 17:41
@charithaT07 charithaT07 merged commit c8a9e77 into main Mar 17, 2026
5 checks passed
@charithaT07 charithaT07 deleted the W-21461342-Configurable-safety-levels branch March 17, 2026 18:57
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.

Add *safe* global option

2 participants