|
| 1 | +--- |
| 2 | +gem: shakapacker |
| 3 | +ghsa: 96qw-h329-v5rg |
| 4 | +url: https://github.com/shakacode/shakapacker/security/advisories/GHSA-96qw-h329-v5rg |
| 5 | +title: Shakapacker has environment variable leak via EnvironmentPlugin |
| 6 | + that exposes secrets to client-side bundles |
| 7 | +date: 2026-01-08 |
| 8 | +description: | |
| 9 | + ### Summary |
| 10 | +
|
| 11 | + Since 2017, the default webpack plugins have passed the entire |
| 12 | + `process.env` to `EnvironmentPlugin`. This pattern exposed ALL |
| 13 | + build environment variables to client-side JavaScript bundles |
| 14 | + whenever application code (or any dependency) referenced |
| 15 | + `process.env.VARIABLE_NAME`. |
| 16 | +
|
| 17 | + This is not a regression - the vulnerable code has existed since |
| 18 | + the original Webpacker implementation. No recent code change |
| 19 | + in Shakapacker triggered this issue. |
| 20 | +
|
| 21 | + ### Impact |
| 22 | +
|
| 23 | + Any environment variable in the build environment that is referenced |
| 24 | + in client-side code (including third-party dependencies) is embedded |
| 25 | + directly into the JavaScript bundle. This includes: |
| 26 | +
|
| 27 | + - `DATABASE_URL` - Database credentials |
| 28 | + - `AWS_SECRET_ACCESS_KEY` - AWS credentials |
| 29 | + - `RAILS_MASTER_KEY` - Rails encrypted credentials key |
| 30 | + - `STRIPE_SECRET_KEY`, `TWILIO_AUTH_TOKEN` - Third-party API keys |
| 31 | + - Any other secrets present in the build environment |
| 32 | +
|
| 33 | + **Severity**: Critical - secrets are exposed in publicly accessible |
| 34 | + JavaScript files. |
| 35 | +
|
| 36 | + ### Root Cause |
| 37 | +
|
| 38 | + The original code used: |
| 39 | + ```javascript |
| 40 | + new |
| 41 | + webpack.EnvironmentPlugin(process.env) |
| 42 | + ``` |
| 43 | +
|
| 44 | + This makes every environment variable available for substitution. If |
| 45 | + any code references `process.env.SECRET_KEY`, that value is embedded |
| 46 | + in the bundle. |
| 47 | +
|
| 48 | + ### Patches |
| 49 | +
|
| 50 | + Upgrade to version 9.5.0 or later, which uses an allowlist approach |
| 51 | + that only exposes `NODE_ENV`, `RAILS_ENV`, and `WEBPACK_SERVE` by default. |
| 52 | +
|
| 53 | + ### Workarounds |
| 54 | +
|
| 55 | + If developers cannot upgrade immediately: |
| 56 | + 1. Audit client-side code and dependencies for any `process.env.X` |
| 57 | + references to sensitive variables |
| 58 | + 2. Remove sensitive variables from the build environment |
| 59 | + 3. Override the default plugins with a custom webpack/rspack |
| 60 | + config using an explicit allowlist |
| 61 | +
|
| 62 | + ### Migration |
| 63 | +
|
| 64 | + After upgrading, if client-side code needs access to specific environment |
| 65 | + variables: |
| 66 | +
|
| 67 | + **Option 1: Use the `SHAKAPACKER_PUBLIC_` prefix (recommended)** |
| 68 | + ```bash |
| 69 | + # Variables with this prefix are automatically exposed |
| 70 | + export SHAKAPACKER_PUBLIC_API_URL=\"https://api.example.com\" |
| 71 | + ``` |
| 72 | +
|
| 73 | + **Option 2: Use `SHAKAPACKER_ENV_VARS`** |
| 74 | + ```bash |
| 75 | + SHAKAPACKER_ENV_VARS=API_URL,FEATURE_FLAG |
| 76 | + bundle exec rails assets:precompile |
| 77 | + ``` |
| 78 | +
|
| 79 | + ### Action Required |
| 80 | +
|
| 81 | + After upgrading, **rotate any secrets** that may have been exposed |
| 82 | + in previously compiled JavaScript bundles. |
| 83 | +cvss_v3: 7.5 |
| 84 | +patched_versions: |
| 85 | + - ">= 9.5.0" |
| 86 | +related: |
| 87 | + url: |
| 88 | + - https://github.com/shakacode/shakapacker/security/advisories/GHSA-96qw-h329-v5rg |
| 89 | + - https://github.com/shakacode/shakapacker/pull/857 |
| 90 | + - https://github.com/shakacode/shakapacker/commit/3e06781b18383c5c2857ed3a722f7b91bdc1bc0e |
| 91 | + - https://github.com/advisories/GHSA-96qw-h329-v5rg |
0 commit comments