mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 08:45:58 +03:00
[PR #5963] Add pw.env.setSecret for secure handling of secret variables #5436
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5436
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5963
Author: @adarsh-naik-2004
Created: 3/7/2026
Status: 🔄 Open
Base:
main← Head:main📝 Commits (3)
2dbb4c8feat(scripting): add pw.env.setSecret to handle secret variables securely37f7670chore: revert local sitemap config override29c824ctest(scripting): resolve scoped envs and add setSecret coverage📊 Changes
8 files changed (+553 additions, -422 deletions)
View changed files
📝
packages/hoppscotch-common/src/types/post-request.d.ts(+9 -0)📝
packages/hoppscotch-common/src/types/pre-request.d.ts(+4 -0)📝
packages/hoppscotch-js-sandbox/src/__tests__/utils/shared.spec.ts(+82 -15)📝
packages/hoppscotch-js-sandbox/src/bootstrap-code/post-request.js(+4 -0)📝
packages/hoppscotch-js-sandbox/src/bootstrap-code/pre-request.js(+4 -0)📝
packages/hoppscotch-js-sandbox/src/cage-modules/namespaces/pw-namespace.ts(+7 -0)📝
packages/hoppscotch-js-sandbox/src/types/index.ts(+3 -0)📝
packages/hoppscotch-js-sandbox/src/utils/shared.ts(+440 -407)📄 Description
Closes #5912
This PR introduces the
setSecretAPI method to the scripting sandbox (available in bothpw.envandhopp.envnamespaces). This allows users to programmatically save and update environment secrets from pre-request and post-request scripts, ensuring sensitive data like OAuth tokens are correctly masked in the UI.What's changed
Core Engine: Updated
setEnvinshared.tsto support anisSecretflag.Sandbox Bridge: Added
envSetSecrettoPwNamespaceMethodsandEnvMethodstype definitions.Security Layer: Implemented the
envSetSecretmapping inpw-namespace.tsto bridge thefaraday-cagesandbox with the core engine.Scripting API: Exposed
setSecretinpre-request.jsandpost-request.jsbootstrap code.DX & Tooling: Added
setSecretto Monaco editor type definitions (pre-request.d.tsandpost-request.d.ts) to provide autocomplete and resolve linting errors.Verified
pw.env.setSecret()correctly routes variables to the Secrets tab.Verified standard
pw.env.set()still routes to the Variables tab.Confirmed Monaco editor autocomplete works as expected.
Proof of Functionality
❌ Before (Current Behavior)
Using


pw.env.set()for sensitive data results in the variable being stored in plain text under the Variables tab, leaking the secret.✅ After (This PR)
Using the new


pw.env.setSecret()API correctly routes the variable to the Secrets tab, ensuring sensitive tokens are masked and stored securely.Notes to reviewers
I have ensured that both the legacy Web Worker sandbox and the new
faraday-cageimplementation are updated. Unrelated local configuration changes (like the sitemap generator override) were reverted before submission to ensure a clean diff.Summary by cubic
Adds setSecret to the scripting environment (
pw.envandhopp.env) so scripts can save sensitive values as secrets. Secrets are masked and saved to the Secrets tab; existing set behavior is unchanged.pw.env.setSecret(key, value)andhopp.env.setSecret(key, value).setEnvaccepts anisSecretflag to mark variables as secrets.envSetSecretwired throughfaraday-cageand legacy bootstrap (pre/post scripts).pm.environment/globals/collectionVariables/variables/vaultnow exposesetSecret.setdoesn’t remove the secret flag; added scoped env resolve tests.Written for commit
29c824c7bf. Summary will update on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.