Skip to content

Commit 03aa805

Browse files
authored
Merge pull request #266 from hauserkristof/feature/v4.0.8
Backport CVE-2024-4067 fix from 4.0.6 over 4.0.7
2 parents 07b8870 + 67fcce6 commit 03aa805

File tree

4 files changed

+71
-18
lines changed

4 files changed

+71
-18
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,24 @@ jobs:
1313
matrix:
1414
os: [ubuntu-latest, windows-latest, macos-latest]
1515
node-version: [10, 12, 14, 16, 17]
16+
exclude:
17+
- os: macos-latest
18+
node-version: 10
19+
- os: macos-latest
20+
node-version: 12
21+
- os: macos-latest
22+
node-version: 14
23+
include:
24+
- os: macos-13
25+
node-version: 10
26+
- os: macos-13
27+
node-version: 12
28+
- os: macos-13
29+
node-version: 14
1630

1731
steps:
1832
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
33+
- uses: actions/setup-node@v4
2034
with:
2135
node-version: ${{ matrix.node-version }}
2236
- run: npm install

CHANGELOG.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ Changelog entries are classified using the following labels _(from [keep-a-chang
3232

3333
</details>
3434

35+
## [4.0.8] - 2024-08-22
36+
37+
- backported CVE-2024-4067 fix (from v4.0.6) over to 4.x branch
38+
39+
## [4.0.7] - 2024-05-22
40+
41+
- this is basically v4.0.5, with some README updates
42+
- **it is vulnerable to CVE-2024-4067**
43+
- Updated braces to v3.0.3 to avoid CVE-2024-4068
44+
- does NOT break API compatibility
45+
46+
## [4.0.6] - 2024-05-21
47+
48+
- Added `hasBraces` to check if a pattern contains braces.
49+
- Fixes CVE-2024-4067
50+
- **BREAKS API COMPATIBILITY**
51+
- Should be labeled as a major release, but it's not.
52+
53+
## [4.0.1 - 4.0.5]
54+
3555
## [4.0.0] - 2019-03-20
3656

3757
### Added
@@ -40,7 +60,6 @@ Changelog entries are classified using the following labels _(from [keep-a-chang
4060
- Adds support for `options.onIgnore`. See the readme for details
4161
- Adds support for `options.onResult`. See the readme for details
4262

43-
4463
### Breaking changes
4564

4665
- Require Node.js >= 8.6
@@ -56,9 +75,9 @@ Changelog entries are classified using the following labels _(from [keep-a-chang
5675

5776
Complete overhaul, with 36,000+ new unit tests validated against actual output generated by Bash and minimatch. More specifically, 35,000+ of the tests:
5877

59-
- micromatch results are directly compared to bash results
60-
- in rare cases, when micromatch and bash disagree, micromatch's results are compared to minimatch's results
61-
- micromatch is much more accurate than minimatch, so there were cases where I had to make assumptions. I'll try to document these.
78+
- micromatch results are directly compared to bash results
79+
- in rare cases, when micromatch and bash disagree, micromatch's results are compared to minimatch's results
80+
- micromatch is much more accurate than minimatch, so there were cases where I had to make assumptions. I'll try to document these.
6281

6382
This refactor introduces a parser and compiler that are supersets of more granular parsers and compilers from other sub-modules. Each of these sub-modules has a singular responsibility and focuses on a certain type of matching that aligns with a specific part of the Bash "expansion" API.
6483

@@ -73,20 +92,20 @@ Here are those sub-modules with links to related prs on those modules if you wan
7392

7493
**Added**
7594

76-
- source map support (optionally created when using parse or compile - I have no idea what the use case is yet, but they come for free) (note that source maps are not generated for brace expansion at present, since the braces compiler uses a different strategy. I'll update if/when this changes).
77-
- parser is exposed, so that implementors can customize or override specific micromatch parsers if necessary
78-
- compiler is exposed, so that implementors can customize or override specific micromatch compilers if necessary
95+
- source map support (optionally created when using parse or compile - I have no idea what the use case is yet, but they come for free) (note that source maps are not generated for brace expansion at present, since the braces compiler uses a different strategy. I'll update if/when this changes).
96+
- parser is exposed, so that implementors can customize or override specific micromatch parsers if necessary
97+
- compiler is exposed, so that implementors can customize or override specific micromatch compilers if necessary
7998

8099
**Fixed**
81100

82-
- more accurate matching (passes 100% of Bash 4.3 of the brace expansion and extglob unit tests, as well as all Bash glob tests that are relevant to node.js usage, all minimatch tests, all brace-expansion tests, and also passes a couple of tests that bash fails)
83-
- even safer - micromatch has always generated optimized patterns so it's not subject to DoS exploits like minimatch (completely different than the regex DoS issue, minimatch and multimatch are still openly exposed to being used for DoS attacks), but more safeguards were built into this refactor
101+
- more accurate matching (passes 100% of Bash 4.3 of the brace expansion and extglob unit tests, as well as all Bash glob tests that are relevant to node.js usage, all minimatch tests, all brace-expansion tests, and also passes a couple of tests that bash fails)
102+
- even safer - micromatch has always generated optimized patterns so it's not subject to DoS exploits like minimatch (completely different than the regex DoS issue, minimatch and multimatch are still openly exposed to being used for DoS attacks), but more safeguards were built into this refactor
84103

85104
**Changed**
86105

87-
- the public API of this library did not change in this version and should be safe to upgrade without changing implentor code. However, we have released this as a major version for the following reasons:
88-
- out of an abundance of caution due to the large amount of code changed in this release
89-
- we have improved parser accuracy to such a degree that some implementors using invalid globs have noted change in behavior. If this is the case for you, please check that you are using a valid glob expression before logging a bug with this library
106+
- the public API of this library did not change in this version and should be safe to upgrade without changing implentor code. However, we have released this as a major version for the following reasons:
107+
- out of an abundance of caution due to the large amount of code changed in this release
108+
- we have improved parser accuracy to such a degree that some implementors using invalid globs have noted change in behavior. If this is the case for you, please check that you are using a valid glob expression before logging a bug with this library
90109

91110
## [1.0.1] - 2016-12-12
92111

@@ -102,8 +121,6 @@ Stable release.
102121

103122
First release.
104123

105-
106124
[Unreleased]: https://github.com/jonschlinkert/micromatch/compare/0.1.0...HEAD
107125
[0.2.0]: https://github.com/jonschlinkert/micromatch/compare/0.1.0...0.2.0
108-
109126
[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ const util = require('util');
44
const braces = require('braces');
55
const picomatch = require('picomatch');
66
const utils = require('picomatch/lib/utils');
7-
const isEmptyString = val => val === '' || val === './';
87

8+
const isEmptyString = (v) => v === "" || v === "./";
9+
const hasBraces = (v) => {
10+
const index = v.indexOf("{");
11+
return index > -1 && v.indexOf("}", index) > -1;
12+
};
913
/**
1014
* Returns an array of strings that match one or more glob patterns.
1115
*
@@ -445,7 +449,7 @@ micromatch.parse = (patterns, options) => {
445449

446450
micromatch.braces = (pattern, options) => {
447451
if (typeof pattern !== 'string') throw new TypeError('Expected a string');
448-
if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
452+
if ((options && options.nobrace === true) || !hasBraces(pattern)) {
449453
return [pattern];
450454
}
451455
return braces(pattern, options);
@@ -464,4 +468,6 @@ micromatch.braceExpand = (pattern, options) => {
464468
* Expose micromatch
465469
*/
466470

471+
// exposed for tests
472+
micromatch.hasBraces = hasBraces;
467473
module.exports = micromatch;

test/braces.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22

33
const assert = require('assert');
44
const mm = require('..');
5-
const { isMatch, makeRe } = mm;
5+
const { isMatch, hasBraces } = mm;
66

77
describe('braces', () => {
8+
it("should return true when braces are found", () => {
9+
assert.equal(hasBraces("{foo}"), true);
10+
assert.equal(hasBraces("foo}"), false);
11+
assert.equal(hasBraces("{foo"), false);
12+
assert.equal(hasBraces("a{}b"), true);
13+
assert.equal(hasBraces("abc {foo} xyz"), true);
14+
assert.equal(hasBraces("abc {foo xyz"), false);
15+
assert.equal(hasBraces("abc {foo} xyz"), true);
16+
assert.equal(hasBraces("abc foo} xyz"), false);
17+
assert.equal(hasBraces("abc foo xyz"), false);
18+
assert.equal(hasBraces("abc {foo} xyz {bar} pqr"), true);
19+
assert.equal(hasBraces("abc {foo xyz {bar} pqr"), true);
20+
assert.equal(hasBraces("abc foo} xyz {bar pqr"), false);
21+
});
22+
23+
824
it('should handle extglobs in braces', () => {
925
let fixtures = ['a', 'b', 'c', 'd', 'ab', 'ac', 'ad', 'bc', 'cb', 'bc,d', 'c,db', 'c,d', 'd)', '(b|c', '*(b|c', 'b|c', 'b|cc', 'cb|c', 'x(a|b|c)', 'x(a|c)', '(a|b|c)', '(a|c)'];
1026

0 commit comments

Comments
 (0)