Skip to content

Commit 68ed375

Browse files
committed
Add change of default maxDepth test.
- Check the maxDepth does not change between tests. - Check the default maxDepth can be changed.
1 parent 15dd726 commit 68ed375

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎tests/security/ghsa-554w-wpv2-vw27.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe('GHSA-554w-wpv2-vw27 Security Patch', function() {
1717
return asn1.toDer(obj).getBytes();
1818
}
1919

20+
beforeEach(function() {
21+
// check max depth is the default
22+
assert.equal(asn1.maxDepth, 256);
23+
});
24+
2025
it('should throw a manageable error when default recursion depth is exceeded', function() {
2126
// create a payload just above the default limit (256)
2227
var DANGEROUS_DEPTH = 257;
@@ -41,6 +46,21 @@ describe('GHSA-554w-wpv2-vw27 Security Patch', function() {
4146
}, /ASN.1 parsing error: Max depth exceeded./);
4247
});
4348

49+
it('should still parse valid nested structures with new default limits', function() {
50+
var oldMaxDepth = asn1.maxDepth;
51+
asn1.maxDepth = 258;
52+
53+
// create a payload just above the default limit (256)
54+
var DANGEROUS_DEPTH = 257;
55+
var der = createNestedDer(DANGEROUS_DEPTH);
56+
var buf = util.createBuffer(der);
57+
58+
// verify with new default depth
59+
asn1.fromDer(buf, {strict: true});
60+
61+
asn1.maxDepth = oldMaxDepth;
62+
});
63+
4464
it('should still parse valid nested structures within default limits', function() {
4565
// verify we didn't break default depth functionality
4666
var SAFE_DEPTH = 20;

0 commit comments

Comments
 (0)