FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix exposing of .env variables in Create React App by moos · Pull Request #560 · debug-js/debug · GitHub

/ debug Public

Fix exposing of .env variables in Create React App - #560

Open
moos wants to merge 13 commits into
debug-js:masterfrom
moos:fix-cra-env
Open

Fix exposing of .env variables in Create React App #560
moos wants to merge 13 commits into
debug-js:masterfrom
moos:fix-cra-env

Conversation

moos commented Apr 18, 2018

Copy link
Copy Markdown

Create React Apps have the nifty feature of getting environment variables either from the shell or .env files. These are then resolved and baked into the JS bundle by webpack.

When using debug, the entirety of your .env file gets exposed in the bundle, e.g.:

    function u() {
      var e;
      try {
        e = t.storage.debug
      } catch (e) {
      }
      return !e && "undefined" !== typeof r && "env" in r && (e = Object({
        NODE_ENV: "production",
        PUBLIC_URL: "",
        REACT_APP_FOO: "1"
      }).DEBUG), e
    }

This PR fixes that situation by moving the env access to a separate file that isn't accessed when in browser mode.

Also should resolve #467 (comment).

Copy link
Copy Markdown

Coverage increased (+1.2%) to 75.0% when pulling 3d42235 on moos:fix-cra-env into 22f9932 on visionmedia:master.

1 similar comment

Copy link
Copy Markdown

Coverage increased (+1.2%) to 75.0% when pulling 3d42235 on moos:fix-cra-env into 22f9932 on visionmedia:master.

coveralls commented Apr 18, 2018
edited
Loading

Copy link
Copy Markdown

Coverage increased (+2.2%) to 89.862% when pulling 86c9684 on moos:fix-cra-env into 5c7c61d on visionmedia:master.

Qix- commented Jun 20, 2018

Copy link
Copy Markdown
Member

I'm 👎 on this. It's adding very specific checks where this is really a shortcoming in electron. Is this even still an issue? I know this is kind of an old PR.

Qix- added feature This proposes or provides a feature or enhancement awaiting-response This issue or pull request is awaiting a user's response change-patch This proposes or provides a change that requires a patch release labels Jun 20, 2018

moos commented Aug 30, 2018

Copy link
Copy Markdown
Author

Yup - definitely still an issue. It's not an electron issue -- the code referenced above ends up in CRA bundle that's consumed by the browser, thereby exposing the entirety of CRA app's various .env files to the web site visitor -- clearly, an unintended (and hard-to-detect, unless you analyze the bundle -- I bet most app devs don't do that!) side-effect of .env + debug.

I'd be happy to submit an update if there is interest.

Qix- commented Dec 13, 2018

Copy link
Copy Markdown
Member

Hi, sorry it took so long to get back. Could you rebase please? I'm okay with adding this check.

Qix- added this to the 5.x milestone Dec 19, 2018
Comment thread karma.conf.js
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
reporters: ['mocha'],

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

So we can see that browser env was selected.

Comment thread package.json Outdated
"scripts": {
"lint": "xo",
"test": "npm run test:node && npm run test:browser",
"test": "npm --node run test:node && npm run test:browser && npm --electron run test:electron",

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

--node and --electron get passed to test as process.env.npm_config_node and process.env.npm_config_electron.

Comment thread src/browser.js
}

// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
if (!r && typeof process !== 'undefined' && 'env' in process) {

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is the critical part that was exposing process.env in the browser. It's been pulled out into the electron-specific flow.

Comment thread package.json Outdated
"test:browser": "karma start --single-run",
"test:node": "istanbul cover --dir coverage/node -x test.js node_modules/mocha/bin/_mocha",
"test:electron": "istanbul cover --dir coverage/electron -x test.js node_modules/mocha/bin/_mocha",
"posttest": "istanbul report --include coverage/**/coverage.json",

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

combines coverage for node + electron.

moos commented Feb 3, 2019

Copy link
Copy Markdown
Author

holy 🐟 -- let's hope I don't have to do that again!

moos commented Feb 27, 2019

Copy link
Copy Markdown
Author

Ping! Would hate to see this become stale again.

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

Labels

awaiting-response This issue or pull request is awaiting a user's response change-patch This proposes or provides a change that requires a patch release feature This proposes or provides a feature or enhancement

Development

Successfully merging this pull request may close these issues.

webpack.DefinePlugin and process.env.DEBUG

3 participants


Back | FazBrowse Home | New Git URL