Skip to content

Commit e8dec57

Browse files
authored
Upgrade @hotwired/turbo-rails to resolve security warning (#3734)
Details of the security vulnerability are available at: GHSA-qppm-g56g-fpvp > A race condition in Turbo Frames allows delayed HTTP responses to > restore stale session cookies after session-modifying operations. As a result, my project started receiving the following warning: > Dependabot cannot update @hotwired/turbo to a non-vulnerable version > > The latest possible version that can be installed is 7.3.0 because of the following conflicting dependencies: > > rails_admin@3.3.0 requires @hotwired/turbo@^7.3.0 via @hotwired/turbo-rails@7.3.0 > No patched version available for @hotwired/turbo > > The earliest fixed version is 8.0.21.
1 parent 07b2066 commit e8dec57

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@fortawesome/fontawesome-free": ">=5.15.0 <7.0.0",
20-
"@hotwired/turbo-rails": "^7.1.0",
20+
"@hotwired/turbo-rails": "^8.0.21",
2121
"@popperjs/core": "^2.11.0",
2222
"@rails/ujs": "^7.1.3-4",
2323
"bootstrap": "^5.1.3",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
11
const { environment } = require("@rails/webpacker");
2+
const path = require("path");
3+
4+
const babelConfig = path.resolve(__dirname, "../../babel.config.js");
5+
const hotwiredPackages = /node_modules\/@hotwired\/turbo(?:-rails)?\//;
6+
const babelLoader = environment.loaders.get("babel");
7+
const babelUse = babelLoader.use[0];
8+
const babelExclude = babelLoader.exclude;
9+
const nodeModulesLoader = environment.loaders.get("nodeModules");
10+
const nodeModulesUse = nodeModulesLoader.use[0];
11+
const nodeModulesExclude = nodeModulesLoader.exclude;
12+
13+
babelUse.options.configFile = babelConfig;
14+
babelLoader.include.push(hotwiredPackages);
15+
babelLoader.exclude = (modulePath) => {
16+
if (hotwiredPackages.test(modulePath)) {
17+
return false;
18+
}
19+
return babelExclude.test(modulePath);
20+
};
21+
22+
nodeModulesUse.options.configFile = babelConfig;
23+
nodeModulesUse.options.babelrc = false;
24+
nodeModulesLoader.exclude = (modulePath) => {
25+
if (hotwiredPackages.test(modulePath)) {
26+
return true;
27+
}
28+
return nodeModulesExclude.test(modulePath);
29+
};
230

331
module.exports = environment;

spec/dummy_app/config/webpacker.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ default: &default
1010

1111
# Additional paths webpack should lookup modules
1212
# ['app/assets', 'engine/foo/app/assets']
13-
additional_paths: ["node_modules/rails_admin/src"]
13+
additional_paths:
14+
- node_modules/rails_admin/src
15+
- node_modules/@hotwired/turbo
16+
- node_modules/@hotwired/turbo-rails
1417

1518
# Reload manifest.json on all requests so we reload latest compiled packs
1619
cache_manifest: false

spec/dummy_app/webpack.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,21 @@ module.exports = {
1818
maxChunks: 1,
1919
}),
2020
],
21+
module: {
22+
rules: [
23+
{
24+
test: /\.(js|mjs)$/,
25+
include: [
26+
path.resolve(__dirname, "app/javascript"),
27+
/node_modules\/@hotwired\/turbo(?:-rails)?\//,
28+
],
29+
use: {
30+
loader: "babel-loader",
31+
options: {
32+
configFile: path.resolve(__dirname, "babel.config.js"),
33+
},
34+
},
35+
},
36+
],
37+
},
2138
};

0 commit comments

Comments
 (0)