fix: resolve artifact-env-leak false positives for node_modules and public tokens - #1740
Draft
skoshx wants to merge 2 commits into
Draft
fix: resolve artifact-env-leak false positives for node_modules and public tokens#1740skoshx wants to merge 2 commits into
skoshx wants to merge 2 commits into
Conversation
… tokens - Extend maskSourceComments to parse sourcemap JSON and mask comments in node_modules sources, fixing false positives from vendor library JSDoc examples (e.g. @reatom/core DATABASE_URL example) - Add _[A-Z0-9]+_PUBLIC_(TOKEN|KEY|SECRET) pattern to trusted public env names, exempting intentionally-public tokens like VITE_STYTCH_PUBLIC_TOKEN that pair a public-env prefix with PUBLIC as a distinct infix - Pattern requires at least one component between underscore and PUBLIC to avoid matching PUBLIC in NEXT_PUBLIC_/EXPO_PUBLIC_ prefixes themselves - Add regression tests covering both sourcemap masking and public token trust Closes #1738 Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Co-authored-by: Skosh <skoshx@users.noreply.github.com>
commit: |
Contributor
Interactive terminal E2ETerminal Control verified the built CLI at
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two false positive cases in the
artifact-env-leaksecurity scan rule:node_moduleslibraries (e.g.,@reatom/corewith hypotheticalprocess.env.DATABASE_URLusage) were flagged when included in sourcemapsourcesContentVITE_STYTCH_PUBLIC_TOKEN(analogous to Stripe'sPUBLISHABLE_KEY) were flagged despite havingPUBLICin their nameRoot Cause
Issue 1: node_modules in sourcemaps
sourcesContentwith original source from all bundled files, includingnode_modulesmaskSourceCommentsfunction returned sourcemaps unchanged (they're JSON, not JS/TS)Issue 2: Public token pattern
VITE_STYTCH_PUBLIC_TOKENmatchesVITE_*_TOKENbut wasn't explicitly trustedPUBLISHABLEpattern,*_PUBLIC_*tokens should be trustedChanges
Extended
maskSourceCommentsfor sourcemaps:.mapfiles and parses as JSONsourcesContententry from anode_modulessource, masks comments individuallyAdded pattern-based trust for public tokens:
_[A-Z0-9]+_PUBLIC_(TOKEN|KEY|SECRET)_andPUBLICto avoid matchingNEXT_PUBLIC_/EXPO_PUBLIC_prefixesVITE_STYTCH_PUBLIC_TOKEN(trusted - has_STYTCH_PUBLIC_TOKEN)NEXT_PUBLIC_STRIPE_PUBLIC_KEY(trusted - has_STRIPE_PUBLIC_KEY)NEXT_PUBLIC_SECRET_TOKEN(still flags - no_X_PUBLIC_pattern)Testing
artifact-env-leaktests pass (45 tests)check-security-scanfixture tests pass (151 tests)Scope Decision
Narrowly scoped to:
node_modulessources within sourcemaps (app code still scanned)_PUBLIC_as a distinct infix (not part of the prefix)Closes #1738