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

fix: resolve opts when no-config & fix vulns #1024

Merged
merged 5 commits into from Aug 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions bin/utils/convert-argv.js
Expand Up @@ -128,28 +128,32 @@ module.exports = function(...args) {
}

if (!configFileLoaded) {
return processConfiguredOptions({});
return processConfiguredOptions(null);
} else if (options.length === 1) {
return processConfiguredOptions(options[0]);
} else {
return processConfiguredOptions(options);
}

function processConfiguredOptions(options) {
const webpackConfigurationValidationErrors = validateSchema(webpackConfigurationSchema, options);
if (webpackConfigurationValidationErrors.length) {
const error = new WebpackOptionsValidationError(webpackConfigurationValidationErrors);
console.error(error.message, `\nReceived: ${typeof options} : ${JSON.stringify(options, null, 2)}`);
process.exit(-1); // eslint-disable-line
if (options) {
const webpackConfigurationValidationErrors = validateSchema(webpackConfigurationSchema, options);
if (webpackConfigurationValidationErrors.length) {
const error = new WebpackOptionsValidationError(webpackConfigurationValidationErrors);
console.error(error.message, `\nReceived: ${typeof options} : ${JSON.stringify(options, null, 2)}`);
process.exit(-1); // eslint-disable-line
}
} else {
options = {};
evenstensberg marked this conversation as resolved.
Show resolved Hide resolved
}

// process Promise
if (typeof options.then === "function") {
if (options && typeof options.then === "function") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you have the if/else, options will never be undefined right? So this additional check is not needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks for options.then object prop so will throw. We're setting props on the object later these checks, I think we "assumed" we either found or did not find the props before validating args that aren't protected by 0CJS (entry and output)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not talking about .then, I'm talking about options &&. It's redundant. You already assigned it before with options = {}.

So or you keep this check and remove the assignment or keep the assignment and remove the check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out, changed now!

return options.then(processConfiguredOptions);
}

// process ES6 default
if (typeof options === "object" && typeof options.default === "object") {
if (options && typeof options === "object" && typeof options.default === "object") {
return processConfiguredOptions(options.default);
}

Expand Down