Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectively short-circuit rendering instead of always doing so when requires are detected [SEC-1323] [INS-4963] #8367

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions packages/insomnia/src/common/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,24 @@ export async function render<T>(
) {
// Do nothing to these types
} else if (typeof x === 'string') {
// Detect if the string contains a require statement
if (/require\s*\(/ig.test(x)) {
console.warn('Short-circuiting `render`; string contains possible "require" invocation:', x);
Sentry.captureException(new Error(`Short-circuiting 'render'; string contains possible "require" invocation: ${x}`));
return x;
// Allowed modules could have valid use cases within templates, and we know for a fact that these modules cannot be
// used as part of an exploit.
const allowedModules = ['crypto', 'path'];
const matches = [...x.matchAll(/require\s*\(\s*["'`]([^'"`]*)['"`]/gi)].map(match => match[1]);

if (matches.length) {
// Only allow the string to be rendered if required modules are *all* in the allowed modules list. If any modules
// outside of the allowed list is detected, we short-circuit rendering and return the raw string.
for (const match of matches) {
if (allowedModules.includes(match)) {
continue;
} else {
console.warn('Short-circuiting `render`; string contains at least one disallowed "require" invocation:', x);
Sentry.captureException(new Error(`Short-circuiting 'render'; string contains at least one disallowed "require" invocation: ${x}`));

return x;
}
}
}

try {
Expand Down
Loading