8000 Less throws for problematic arguments by shadowspawn · Pull Request #88 · minimistjs/minimist · GitHub
[go: up one dir, main page]

Skip to content

Less throws for problematic arguments - #88

Open
shadowspawn wants to merge 5 commits into
minimistjs:mainfrom
shadowspawn:less-throws-for-problematic-arguments
Open

shadowspawn wants to merge 5 commits into
minimistjs:mainfrom
shadowspawn:less-throws-for-problematic-arguments

Conversation

@shadowspawn
@shadowspawn shadowspawn commented Sep 27, 2026 •
Copy link
Copy Markdown
Member

Problem

Certain problematic arguments passed to .parse() could cause Minimist to throw.

#47 reported that passing Object property names such as --toString, --hasOwnProperty, --constructor, --__proto__ caused an expection.

waydeshi from PayPal Cyber Security Team reported privately a couple of similar cases:

  • dotted options overwriting existing number or string in parse results
  • dotted options overwriting argv._ properties on the parse results, particularly setting _.length to something invalid. (argv._ holds the positionals.)

Further related case noted by me:

  • dotted options overwriting existing array in parse results adds properties to array. Not a crash, but not by design.

Solution

Using option names which are also Object properties:

  • the internal bools, strings, and aliases now use null prototype
  • the lookup for previous value in setKey now only considers own properties

Dotted options overwriting number/string/array in parse results:

  • use new empty object in setKey when traversing the dotted option keys and overwriting left-over from previous parsing, which might be a number or string or array.

Dotted options overwriting _ in parse results:

  • ignore writes to _ and _.* in setKey. Simple and effective. Don't muck with the returned positionals.

Threat Model

These are being fixed as bugs rather than a CVE. Quoting comment from @ljharb:

Minimist is a CLI tool framework. If you're crafting args, you're attacking yourself.

- dotted overwrite of number or string
- Object prototype property names
- dotted modifiation of _ properties
@shadowspawn
shadowspawn marked this pull request as draft September 27, 2026 04:53
@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.82%. Comparing base (6715df1) to head (c38d2a5).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
index.js 93.75% 1 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   98.78%   98.82%   +0.03%     
==========================================
  Files           1        1              
  Lines         165      170       +5     
  Branches       70       73       +3     
==========================================
+ Hits          163      168       +5     
  Misses          2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shadowspawn
shadowspawn marked this pull request as ready for review September 27, 2026 05:16
@shadowspawn
Copy link
Copy Markdown
Member Author

I had a look at the action failure, but didn't work out the cause. It appears to be failing "Pre Harden Runner" in the "node tests".

https://github.com/ljharb/actions/blob/527f3f7e20d7ed257dbc9d9ed55c9a33570583bb/.github/workflows/node.yml#L499

Comment thread index.js Resolved
@shadowspawn
Copy link
Copy Markdown
Member Author

I was not sure what to produce when dotted option is added after a previous non-option value. I considered wrapping in an array to preserve previous value, but thought it was a bit too complicated to receive and went with simple overwrite.

After looking again at existing minimist behaviour, and at yargs-parser behaviour (some differences), both will produce array with embedded object in various circumstances.

I do not think these mixed option types are important use cases, but do prefer the behaviour to be self-consistent. I'm going to have another think about it... (Going back to draft.)

Minimist example of array wrap, behaviour not affected by PR:

% node plain.js --a.b=VALUE --a                 
{ _: [], a: [ { b: 'VALUE' }, true ] }

@shadowspawn
shadowspawn marked this pull request as draft September 27, 2026 21:16
@shadowspawn
Copy link
Copy Markdown
Member Author

I decided to keep the setKey preparation for dotted option names simple. Don't try and preserve previous values by wrapping value in array, just discard previous value and add an empty object for the incoming value.

For reference, the yargs-parser array related code in the dotted notation processing is:

https://github.com/yargs/yargs-parser/blob/913df9d1ddbea131e38516c09c2a81eb15c69968/lib/yargs-parser.ts#L822-L828

@shadowspawn
shadowspawn marked this pull request as ready for review October 5, 2026 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0