-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(conditional-page-builds): track potentially unsafe Node.js built…
…in modules usage (#29560) * feat(conditional-page-builds): track potentially unsafe Node.js builtin modules usage * test(artifacts): add test case for tracking usage of fs in ssr * Update packages/gatsby/src/utils/webpack.config.js Co-authored-by: Ward Peeters <ward@coding-tech.com> * Update packages/gatsby/src/commands/build-html.ts Co-authored-by: Ward Peeters <ward@coding-tech.com> * Update packages/gatsby/src/commands/build-utils.ts Co-authored-by: Ward Peeters <ward@coding-tech.com> Co-authored-by: Ward Peeters <ward@coding-tech.com>
- Loading branch information
Showing
21 changed files
with
627 additions
and
324 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background: yellow; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import PostBodyComponents from "./src/components/post-body-components-ssr" | ||
import * as React from "react" | ||
import * as fs from "fs" | ||
|
||
export function onRenderBody({ setPostBodyComponents }) { | ||
setPostBodyComponents(PostBodyComponents) | ||
export function onRenderBody({ setHeadComponents }) { | ||
setHeadComponents( | ||
<style | ||
dangerouslySetInnerHTML={{ | ||
__html: `body {\nbackground: white;\n}`, | ||
}} | ||
/> | ||
) | ||
} |
7 changes: 0 additions & 7 deletions
7
integration-tests/artifacts/src/components/post-body-components-ssr.js
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
4 changes: 4 additions & 0 deletions
4
packages/gatsby/cache-dir/ssr-builtin-trackers/child_process.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable filenames/match-regex */ | ||
const { wrapModuleWithTracking } = require(`./tracking-unsafe-module-wrapper`) | ||
|
||
module.exports = wrapModuleWithTracking(`child_process`) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { wrapModuleWithTracking } = require(`./tracking-unsafe-module-wrapper`) | ||
|
||
module.exports = wrapModuleWithTracking(`fs`) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { wrapModuleWithTracking } = require(`./tracking-unsafe-module-wrapper`) | ||
|
||
module.exports = wrapModuleWithTracking(`http`) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { wrapModuleWithTracking } = require(`./tracking-unsafe-module-wrapper`) | ||
|
||
module.exports = wrapModuleWithTracking(`http2`) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { wrapModuleWithTracking } = require(`./tracking-unsafe-module-wrapper`) | ||
|
||
module.exports = wrapModuleWithTracking(`https`) |
37 changes: 37 additions & 0 deletions
37
packages/gatsby/cache-dir/ssr-builtin-trackers/tracking-unsafe-module-wrapper.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// initializing global here for unsafe builtin usage at import time | ||
global.unsafeBuiltinUsage = [] | ||
|
||
function createProxyHandler(prefix) { | ||
return { | ||
get: function (target, key) { | ||
const value = target[key] | ||
if (typeof value === `function`) { | ||
return function wrapper(...args) { | ||
const myErrorHolder = { | ||
name: `Unsafe builtin usage ${prefix}.${key}`, | ||
} | ||
Error.captureStackTrace(myErrorHolder, wrapper) | ||
|
||
global.unsafeBuiltinUsage.push(myErrorHolder.stack) | ||
return value.apply(target, args) | ||
} | ||
} else if (typeof value === `object` && value !== null) { | ||
return new Proxy( | ||
value, | ||
createProxyHandler( | ||
key && key.toString ? `${prefix}.${key.toString()}` : prefix | ||
) | ||
) | ||
} | ||
|
||
return value | ||
}, | ||
} | ||
} | ||
|
||
function wrapModuleWithTracking(moduleName) { | ||
const mod = require(moduleName) | ||
return new Proxy(mod, createProxyHandler(moduleName)) | ||
} | ||
|
||
exports.wrapModuleWithTracking = wrapModuleWithTracking |
Oops, something went wrong.