-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbenchmark.html
618 lines (615 loc) · 26.8 KB
/
benchmark.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ReDoS-Test for JavaScript (18.10.31)</title>
<meta name="Author" content="Achim Hoffmann">
<meta name="Generator" content="me using vi ;-)">
<meta name="DC.Creator" content="redos @at@ my -dash- stp .dot. net">
<meta name="DC.Date" content="2009-10-20">
<meta name="DC.SCCS" content="@(#) benchmark.html %i% 20/10/16 14:47:01">
<meta name="DC.Source" content="@(#) benchmark.html $Id$">
<meta name="DC.Identifier" content="git://github .dot. com/EnDe/ReDoS (dot) git">
<meta name="DC.Title" content="ReDoS-Test for JavaScript">
<meta name="DC.Description" content="ReDoS-Test for JavaScript">
<meta name="DC.Language" content="en">
<meta name="DC.Rights" content="Creative Commons 3.0, http://creativecommons.org/licenses/by-sa/3.0/">
<script language="JavaScript" type="text/javascript">
//<![CDATA[
var ReDoS = {
'VERSION': '18.10.31',
/*
* 18.10.31 typos fixed
* 14.05.07
*/
/* DESCRIPTION
* All RegEx and payloads are defined in this ReDoS{} object.
* There're 2 functions in ReDoS: .testmatch() .testreplace()
* to perform the test. These functions call rxm() and rxr().
*
* +---------------+ +---------------+
* | functions | | data |
* | - - - - - - - | | - - - - - - - |
* |---------------| |---------------|
* | .testXXXXX(i) |--->--->initialize-->--> .tests[i] |
* +---------------+ | +- .rex |
* / | +- .pay |
* / | +- .... |
* | +---------------+ | +- .XXXXX |
* |--| .rxX(i) |--->set values-->--> +- .Xt0 |
* \ +---------------+ | +- .Xt1 |
* / +---------------+ | |
* |--| .GUI.setX(i) |<---get values--<--< |
* | +---------------+ +---------------+
* \---- called with setTimeout()
*
* All variables and functions in ReDoS.GUI* are for building
* and updating the DOM (HML tags).
*
* Note about setTimeout() call:
* The setTimeout() calls are used to simulate threading. This
* avoids a completely hanging browser if any call to match()
* or replace() consumes all time.
* 1st setTimout() calls the .match() or .replace()
* 2nd setTimout() calls a GUI function to display values
* For gecko-based browsers the first argument of setTimeout()
* must be enclosed in " (double quotes), otherwise a syntax
* error is thrown.
* Most other browsers accept the first argument without these
* quotes, but work with quotes too, hence we use the them.
*
*/
/*****************************************************************
** constants
*****************************************************************/
'timeout': 3000, // default: 3 seconds
/*****************************************************************
** payloads and RegExp pattern
*****************************************************************/
/* we use RegExp instead of string objects to avoid escaping
* see ReDoS.payload2str() to cast to string again
*/
'patterns': [], // this array used for working
'payloads': [], // this array used for working
'payloads_default': [ // built-in defaults
/aaaaaaaaaaaaX/,
/aaaaaaaaaaaaaaaaaaX/,
/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX/,
/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX/,
/aaaaaaaaaa/,
/aaaaaaaaaaaaaaaaaaaa/, // Cox
/aaaaaaaaaaaaaaaaaaaaaaaaa/, // Cox
/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/, // Cox
/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!/, // Java Classname
/a@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!/, // email validation
/a@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX/, //
/(.+)+\u0001/, // invalid escape sequence
'[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,', // DataVault
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"/, // EntLib
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"x/, //
null ],
'patterns_default': [ // built-in defaults
/(a+)+/,
/([a-zA-Z]+)*/,
/(a|aa)+/,
/(a|a?)+/,
/(.*a){11}/,
/* 5*/ /(.*a){65}/,
/([^\\"']+)*/, // Friedl
//----------------------------------------------------------------------
/* same as above again enclosed in ^and $ ... */
/* 7*/ /^(a+)+$/,
/* 8*/ /^([a-zA-Z]+)*$/,
/^(a|aa)+$/,
/*10*/ /^(a|a?)+$/,
/*11*/ /^(.*a){11}$/,
/*12*/ /^(.*a){65}$/,
/^([^\\"']+)*$/,
//----------------------------------------------------------------------
/*14*/ /^[a-zA-Z]+(([\'\,\.\-][a-zA-Z ])?[a-zA-Z]*)*$/, // OWASP
/*15*/ /^\[(,.*)*\]$/, // DataVault
/^([^\"]+)(?:\\([^\"]+))*$/, // EntLib
/^(([a-z])+.)+[A-Z]([a-z])+$/, // Java Classname
/a?a?a?a?a?a?a?a?a?a?aaaaaaaaaa/, // Cox
/*19*/ /a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaa/, // Cox
null ],
'nohang':{
'Mac OS X':['Webkit', 'Safari4', 'Shiira2.2', 'iCab4.7', 'OmniWeb5.10' ],
'Windoze': ['Webkit', 'Safari4' ]
}, // nohang
/* following just rough lists as not all pattern fail with all payloads */
'hang':{
'Mac OS X':['FF2', 'FF3', 'Opera10', 'Camino', 'Sunrise1.8' ],
'Windoze': ['FF2', 'FF3', 'Opera10', 'Chrome' ], // Mozilla 1.7 hangs partially
'Linux': ['FF2', 'FF3', 'Opera10' ],
'FF2': [5, 7, 8, 10, 11, 12, 14, 15, 19],
'Opera10': [5, 7, 8, 10, 11, 12, 14, 15, 19],
'Camino': [5, 7, 8, 10, 11, 12, 14, 15, 19],
'Chrome': [5, 7, 8, 10, 11, 12, 14, 15, 19]
}, // hang
'datatyp': '', // contains filename and number of RegEx and payloads
'set_data': function(f){ // set working arrays, use *_default if f empty
var i;
while(ReDoS.payloads.pop()!==undefined){}; ReDoS.payloads = new Array();
while(ReDoS.patterns.pop()!==undefined){}; ReDoS.patterns = new Array();
if (f==='') {
ReDoS.datatyp = 'data: built-in';
//ReDoS.payloads = ReDoS.payloads_default; // does not work in all browsers :-(
for (i=0; i<ReDoS.payloads_default.length; i++) { ReDoS.payloads.push(ReDoS.payloads_default[i]); }
for (i=0; i<ReDoS.patterns_default.length; i++) { ReDoS.patterns.push(ReDoS.patterns_default[i]); }
} else {
ReDoS.datatyp = 'data: "' + f + '"';
ReDoS.readfile(f);
}
}, // set_data
/*****************************************************************
** read RegEx patterns and payloads
*****************************************************************/
'readfile': function(file){ // read from file
/* SYNTAX
* The syntax in the file (see ReDoS.txt also) is as follows:
*
* empty lines are ignored
* lines starting with # are comments and ignored
* all other lines are data lines
*
* Data lines have following format:
*
* keyTABvalue
*
* where TAB is the ASCII TAB character (hex 0x09).
* key is any alphanumeric string, following keywords are special
* payloads - start of list with payloads
* patterns - start of list with RegEx patterns
* The value of these keywords may be any string.
* All other lines are either payloads or patterns. The left column is
* just a descriptive keyword. The right column is either a string for
* the payload or the raw string as RegEx (without delimiters like /).
*
* EXAMPLE
* payloads following lines are payloads
* str1 foo
* str2 bar
* patterns following lines are raw RegEx
* regex1 ^a|b
* regex2 ^b|a
*/
var t = '';
var x = new XMLHttpRequest();
var r = x.open("GET", file, false);// load synchronous, to avoid specifying a handler
x.setRequestHeader('Accept', 'text/plain'); // workaround for some picky browsers reading from file:///
r = x.send(null);
t = x.responseText;
if ((t===null) || ((x.status!==200) && (x.status!==0))) {
// 200 from http:// request; 0 from file:/// request
t = null; x = null;
alert('**ERROR: reading ' + file + ' failed');
return;
}
//#dbx# alert(t);
var m = '';
var c = null;
var l = '';
var s = t.split('\n');
while ((l = s.shift())!==undefined) {
if (l.match(/^\s*#/)!==null) { continue; } // skip comments
if (l.match(/^\s*$/)!==null) { continue; } // skip empty lines
l = l.replace(/\t{2,}/g, '\t'); // squeeze multiple TABs
c = l.split(/\t/);
switch (c[0]) { // only have 2 keywords, anything else is data
case 'payloads':
case 'patterns': m = c[0]; break;
default:
switch(m) {
case 'payloads': ReDoS.payloads.push(c[1]); break;
case 'patterns': ReDoS.patterns.push(c[1]); break;
default: /* simply ignore */ break;
}
}
}
}, // fileread
/*****************************************************************
** string functions
*****************************************************************/
'payload2str': function(r){
if (typeof(r)==='function'){ // RegExp are of object type function
return r.toString().substring(1,r.toString().length-1);
}
if (typeof(r)==='object'){ // .. but some browser use object :-(
return r.toString().substring(1,r.toString().length-1);
}
return r;
}, // payload2str
'escape': function(r){ // browser built-ins are too stupid, sometimes
return r.replace(/[^a-zA-Z0-9;,:._#'+*~!"§$%\/()=?{}\[\]\\ |-]/gi,function(c){return '%'+parseInt(c.charCodeAt(),10).toString(16);});
return r;
}, // escape
/*****************************************************************
** tests
*****************************************************************/
't0': function() {return ((new Date().getTime())); },
't1': function(t){return ((new Date().getTime()) - t); },
'tests':{ // hash containing all tests
'sample':{ // '"sample" is base id of row in table where to show results',
'rex': 'RegExp pattern',
'pay': 'payload to be used for RegExp',
'mt0': 'contains start time in mili-seconds for match()',
'rt0': 'contains start time in mili-seconds for replace()',
'mt1': 'contains end time in mili-seconds for match()',
'rt1': 'contains end time in mili-seconds for replace()',
'cnt': 'number of substitutions done by replace()',
'matches': 'contains the result of pay.match(reg);',
'merror': 'catched errors and exceptions in match()',
'replace': 'contains the result of pay.replace(reg,"X");',
'rerror': 'catched errors and exceptions in replace()'
}
}, // tests
/* for following functions the input parameter must be key of above tests' hash */
'rxm': function(i){ // .match() for given testcase
var t = this.tests[i];
var a = null;
var p = this.payload2str(t.pay);
try {
t.mt0 = this.t0();
var a = p.match(t.rex);
t.mt1 = this.t1(t.mt0);
t.matches = a;
} catch(e) { t.merror = e; }
t = null; p = null;
}, // rxm
'rxr': function(i){ // .replace() for given testcase
var t = this.tests[i];
var a = null;
var p = this.payload2str(t.pay);
var c = 0; // .replace() can not count the substitutions itself
try {
t.rt0 = this.t0();
var a = p.replace(new RegExp(this.payload2str(t.rex),'g'), function(){c++;return 'R';});
t.rt1 = this.t1(t.rt0);
t.cnt = c;
t.replace = a;
} catch(e) { t.rerror = e; }
t = null; p = null;
}, // rxr
/*****************************************************************
** GUI functions
*****************************************************************/
'GUI':{
'self': this,
'rows': 0, // count rows for RegEx
'view': 'Payload', // group table by Payload or RegExp
'btn':function(t,c,i,u,p){ // create table TH or TD cell with button
// ugly hack with u parameter
var d = this.td(t, null, i, null, '');
if (c!==null) { d.setAttribute('class',c); }
var b = document.createElement('BUTTON');
b.value = i;
if ((p==='m')||(p==='M')){
if (u===null) { // just one regex
b.setAttribute('onClick','ReDoS.GUI.testmatch("'+i+'",null); return false;');
b.title = 'test with .match()';
} else { // all regex
b.setAttribute('onClick','ReDoS.GUI.testmatch("*", "'+i+'"); return false;');
b.title = u;
}
}
if ((p==='r')||(p==='R')){
if (u===null) { // just one regex
b.setAttribute('onClick','ReDoS.GUI.testreplace("'+i+'",null);return false;');
b.title = 'test with .replace()';
} else { // all regex
b.setAttribute('onClick','ReDoS.GUI.testreplace("*", "'+i+'");return false;');
b.title = u;
}
}
if ((p==='x')||(p==='X')){
b.setAttribute('onClick','ReDoS.GUI.check_use("' + i + '");return false;');
}
if (u!==null) { b.title = u; } // overwrite above defaults
b.appendChild(document.createTextNode(p));
d.appendChild(b);
return d;
}, // btn
'td':function(t,c,i,u,p){ // create table TH or TD cell
var d = document.createElement(t);
if (i!==null) { d.id = i; }
if (u!==null) { d.title = u; }
if (c!==null) { d.setAttribute('class',c); }
d.appendChild(document.createTextNode(p));
return d;
}, // td
'hd':function(i,p){ // create (sub)table header row
var t = document.createElement('TR');
t.appendChild(this.btn('TH', 'b', i, 'toggle all checkboxes for: '+ReDoS.payload2str(p), 'x'));
t.appendChild(this.td( 'TH', 'h', null, null, ' '));
t.appendChild(this.btn('TH', 'b', ReDoS.payload2str(p), 'test all RegExp with .match()', 'M'));
t.appendChild(this.btn('TH', 'b', ReDoS.payload2str(p), 'test all RegExp with .replace()','R'));
d = document.createElement('TH');
d.setAttribute('class','str');
d.colSpan = 2;
d.title = 'length: '+ ReDoS.payload2str(p).length;
d.appendChild(document.createTextNode( ReDoS.payload2str(p) ));
t.appendChild(d);
delete d; d = null;
return t;
}, // hd
'tr':function(i,r,p){ // create table row
/* +---+--------+---+-----+-------+---------------------+
* |use| regex | |time | count | strings | # if r===null && p===null
* +---+--------+---+-----+-------+---------------------+
* | | |[m]| | | | # if r!==null
* |(x)| regex |---+-----+-------+---------------------+
* | | |[r]| | | | # if r===null
* +---+--------+---+-----+-------+---------------------+
*/
var txt = (r===null) ? 'r' : 'm';
var t = document.createElement('TR');
if ((r===null)&&(p===null)){
t.appendChild(this.btn('TH','e2', 'p\\\\d+', 'toggle all checkboxes for all strings', 'X'));
t.appendChild(this.td('TH',null,null, null,((this.view==='Payload')?'RegExp':'string') ));
t.appendChild(this.td('TH','e2',null, null, ' ' ));
t.appendChild(this.td('TH','e2',null,'elapsed time in ms', 'time' ));
t.appendChild(this.td('TH','e2',null,'number of matches/replaces', 'count' ));
t.appendChild(this.td('TH',null,null,'result of match/replace', ((this.view==='Payload')?'string':'RegExp') ));
return t;
}
var d = null;
var x = null;
var a = 'Replace.';
if (r!==null){
this.rows++;
a = 'Match.';
d = document.createElement('TD');
d.rowSpan = 2;
x = document.createElement('INPUT');
x.id = i + '.use'; x.type = 'checkbox'; x.checked = true; x.title = i;
x.setAttribute('onClick','ReDoS.GUI.use("'+i+'",this.checked);');
d.appendChild(x);
t.appendChild(d);
d = document.createElement('TH');
d.rowSpan = 2;
d.title = 'length: '+ ReDoS.payload2str(r).length;
d.setAttribute('class','rex');
d.appendChild(document.createTextNode( ReDoS.payload2str(r) ));
t.appendChild(d);
}
if ((this.rows%2)===0){ t.setAttribute('class','alt'); }
// create cell in row: tag, class, id, title, text
// ------------------+-----+-----+-------------------+-------------+---------
t.appendChild(this.btn('TD', null, i, null, txt));
t.appendChild(this.td( 'TD', null, (a + 'time.' + i),(a + ' time'), ' '));
t.appendChild(this.td( 'TD', null, (a + 'count.' + i),(a + ' count'),' '));
t.appendChild(this.td( 'TD', null, (a + 'text.' + i), null, ' '));
return t;
}, // tr
'tab':function(){ // create table
var t = document.createElement('DIV');
t.innerHTML = ReDoS.datatyp
+ '<SPAN class="s"> (' + ReDoS.patterns.length + ' RegEx) </SPAN>'
+ '<SPAN class="s"> (' + ReDoS.payloads.length + ' strings) </SPAN>';
document.getElementById('result').appendChild(t); t = null;
var b = document.createElement('TBODY'); b.id = 'tbody';
var p = 0, r = 0, c = 0;
var i = '';
var groups = ReDoS.payloads;
var lines = ReDoS.patterns;
if (this.view==='RegExp'){
groups = ReDoS.patterns;
lines = ReDoS.payloads;
}
for (p=0; p<groups.length; p++){
if (groups[p]===null){ continue; }
i = 'p' + p.toString(10);
b.appendChild( this.hd( i, groups[p] ) );
for (c=0; c<lines.length; c++){
if (lines[c]===null){ continue; }
i = 'p' + p.toString(10) + '.' + c.toString(10);
b.appendChild( this.tr( i, lines[c], groups[p] ) );
b.appendChild( this.tr( i, null, groups[p] ) );
ReDoS.tests[i] = {
'use': true,
'rex': ((this.view==='Payload') ? lines[c] : groups[p]),
'pay': ((this.view==='Payload') ? groups[p] : lines[c]),
'mt0': null,
'rt0': null,
'mt1': null,
'rt1': null,
'cnt': null,
'matches': null,
'merror': null,
'replace': null,
'rerror': null
};
}
} // rows
t = document.createElement('TABLE');
t.appendChild(b);
b = document.createElement('THEAD');
b.appendChild( this.tr( 'head', null, null ) );
t.appendChild(b);
document.getElementById('result').appendChild(t);
delete t; t = null;
//this.testmatch( '*',null);
//this.testreplace('*',null);
}, // tab
'clear': function(){ document.getElementById('result').innerHTML = ''; }, // clear
'use': function(i,val){ ReDoS.tests[i].use = val; }, // use
'groupby': function(val){ this.view = val; this.clear(); this.tab(); return true; }, // groupby
'addpay': function(val){ ReDoS.payloads.push(new RegExp(val)); this.clear(); this.tab(); }, // addpay
'addrex': function(val){ ReDoS.patterns.push(new RegExp(val)); this.clear(); this.tab(); }, // addrex
'setm': function(i){
var r = ReDoS.tests[i];
var t = document.getElementById('Match.time.' +i);
if (t===null) { return; }
if (r.mt1===null){ t.style.background = 'red'; }
t.innerHTML = ((r.mt1===null) ?'~':r.mt1);
t = document.getElementById('Match.text.' +i);
if (r.merror!==null){
t.innerHTML = ReDoS.escape(r.merror.toString());
t.style.background = 'red';
t.title = '<JavaScript runtime exception>';
r = null;
return;
}
document.getElementById('Match.count.'+i).innerHTML = ((r.matches===null)?'-':r.matches.length-1);
t.title = ((r.matches===null)?'<null>':ReDoS.escape(r.matches.toString()));
var s = '';
if (r.matches!==null){
r.matches.shift();
s = r.matches.join(', ');
//while(p.pop()) {};
t.innerHTML = s;
}
r = null;
}, // setm
'setr': function(i,t,p,c){
var r = ReDoS.tests[i];
var t = document.getElementById('Replace.time.' +i);
if (t===null) { return; }
if (r.rt1===null){ document.getElementById('Replace.time.' +i).style.background = 'red'; }
t.innerHTML = ((r.rt1===null) ?'~':r.rt1);
t = document.getElementById('Replace.text.' +i);
if (r.rerror!==null){
t.innerHTML = ReDoS.escape(r.rerror.toString());
t.style.background = 'red';
t.title = '<JavaScript runtime exception>';
r = null;
return;
}
document.getElementById('Replace.count.'+i).innerHTML = r.cnt;
t.innerHTML = r.replace;
t.title = ((r.replace===null)?'<null>':ReDoS.escape(r.replace.toString()));
t = null;
}, // setr
'check_use': function(i){ // toggle "use" checkbox for matching id i
var x = 0;
var t = document.getElementsByTagName('INPUT');
//#dbx# alert(new RegExp(i + '\\.\\d+\\.use'));
for (x=0; x<t.length; x++){ // ids are like p11.23.use
if (t[x].id.match(new RegExp(i + '\\.\\d+\\.use'))===null) { continue; } // skip if not matches
t[x].checked = ! t[x].checked;
}
}, // check_use
'testmatch': function(i,p){ // call .match() for given testcase
/* i='*': use all testcases
* i!=null: use just that testcase
* p!=null: use all testcases with that payload
*/
var x = i;
if (i==='*'){
for (x in ReDoS.tests){
if (x==='sample'){ continue; }
if (ReDoS.tests[x].use===false){ continue; }
if (p!==null) { // group button: use only tests of this group
if (this.view==='Payload'){
if (p!==ReDoS.payload2str(ReDoS.tests[x].pay)){ continue; }
} else {
if (p!==ReDoS.payload2str(ReDoS.tests[x].rex)){ continue; }
}
}
// following does not yet work proper
//setTimeout("(function(a){document.getElementById('mcount').innerHTML=ReDoS.tests[a].pay;ReDoS.rxm(a);})('"+x+"')", 1);
setTimeout("(function(a){ReDoS.rxm(a);})('"+x+"')", 1);
setTimeout("(function(a){ReDoS.GUI.setm(a);})('"+x+"')", ReDoS.timeout);
}
} else {
setTimeout("(function(a){ReDoS.rxm(a);})('"+x+"')", 1);
setTimeout("(function(a){ReDoS.GUI.setm(a);})('"+x+"')", ReDoS.timeout);
}
}, // testmatch
'testreplace': function(i,p){ // call .replace() for given testcase
var x = i;
if (i==='*'){
for (x in ReDoS.tests){
if (x==='sample'){ continue; }
if (ReDoS.tests[x].use===false){ continue; }
if (p!==null) { // group button: use only tests of this group
if (this.view==='Payload'){
if (p!==ReDoS.payload2str(ReDoS.tests[x].pay)){ continue; }
} else {
if (p!==ReDoS.payload2str(ReDoS.tests[x].rex)){ continue; }
}
}
setTimeout("(function(a){ReDoS.rxr(a);})('"+x+"')", 1);
setTimeout("(function(a){ReDoS.GUI.setr(a);})('"+x+"')", ReDoS.timeout);
}
} else {
setTimeout("(function(a){ReDoS.rxr(a);})('"+x+"')", 1);
setTimeout("(function(a){ReDoS.GUI.setr(a);})('"+x+"')", ReDoS.timeout);
}
}, // testreplace
'newtab': function(f){ // replace table with new data
ReDoS.set_data(f);
ReDoS.GUI.clear();
ReDoS.GUI.tab();
}, // newtab
'dumm': null
}, // GUI
'dumm': null
}; //ReDoS
ReDoS.set_data('');
//]]>
</script>
<style type="text/css">
button {padding:0px; color:black;margin:-1px;border-width:1px;min-width:2em;border-radius:4px;}
div {padding-top: 0.2em; }
span.s {font-size: 70%; min-width:20em;}
table {border-collapse:collapse;font-family:monospace;border:1px solid black;}
th {padding-right:0.2em;padding-left:0.2em;}
.e2 {width:2em;}
th.str {background:#5f9; color:#0000ff;}
th.rex {text-align:right; min-width:15em;}
th.a {text-align:right; color:#a0a0a0;}
td {text-align:center; padding-right:0.2em;padding-left:0.2em;border:1px solid black;min-width:2em;}
td:last-child {text-align:left;}
td:first-child {width:1em;}
tbody {overflow-y:auto; width:100%; height:99.9%; }
thead {position:relative; }
thead th{border-left: 1px solid black;color:#a0a0a0;}
tr {border-bottom:1px solid black;}
tr.alt {background:#cfd;}
.note {border:1px solid black;margin:1em;padding:0.1em;}
</style></head>
<body onLoad="return ReDoS.GUI.tab();">
<center><a href="http://github.com/EnDe/ReDoS/" title="ReDoS Home">ReDoS</a>   <small><script>document.write(ReDoS.VERSION);</script></small></center>
<div class="note"><b>Note:</b> This is a simple demo site. Some RegEx may not work proper with JavaScript here 'cause they are crafted for other RegEx engines. Please check your error console.</div>
<table><caption>legend</caption>
<tr><th class="str">-str- </th><td>test string or RegExp (title shows length)</td></tr>
<tr><th class="a"><button>X</button></th><td>test not performed if unchecked; button toggles all checkboxes</td></tr>
<tr><th class="a"><button>x</button></th><td>test not performed if unchecked; button toggles checkboxes of group</td></tr>
<tr><th class="a">time </th><td>time in milli-seconds for test</td></tr>
<tr><th class="a">count </th><td>number of matches or replaces</td></tr>
<tr><th class="a"><button>m</button> <button>r</button></th><td>buttons for .match or .replace (single test)</td></tr>
<tr><th class="a"><button>M</button> <button>R</button></th><td>buttons for .match or .replace (test group)</td></tr>
<tr><th class="rex">RegExp (left)</th><td>regular expression (title shows length)</td></tr>
<tr><th class="rex">string (left)</th><td>test pattern (title shows length)</td></tr>
<tr><th class="a">(-right column-)</th><td>result of test (title shows match or replace escaped)</td></tr>
</table><br>
<div>
<input id="tim" size="2" title="timeout for tests in milli-seconds">  <button onclick="ReDoS.timeout(document.getElementById('tim').value);return false;">set timeout </button><br>
<input id="pay" size="32"> <button onclick="ReDoS.GUI.addpay(document.getElementById('pay').value);return false;">add new Payload</button><br>
<input id="rex" size="32"> <button onclick="ReDoS.GUI.addrex(document.getElementById('rex').value);return false;">add new RegExp </button>
</div>
<script>document.getElementById('tim').value = ReDoS.timeout;</script>
<div>
<button onclick="ReDoS.GUI.clear(); return false;">clear table</button>  
<button onclick="ReDoS.GUI.newtab(''); return false;">load table with built-in data</button>   <br/>
<input id="fil" size="12" type="file"> 
<button onclick="ReDoS.GUI.newtab(document.getElementById('fil').value);return false;">load table with data from file</button>
</div>
<div>
<b>group table by: </b>
<label for="gp" title="list all RegEx for each payload">(payload) string <input id="gp" name="grp" type="radio" value="Payload" onClick="return ReDoS.GUI.groupby(this.value);" checked ></label>
<label for="gr" title="list all payloads for each RegEx">RegExp <input id="gr" name="grp" type="radio" value="RegExp" onClick="return ReDoS.GUI.groupby(this.value);"></label>
</div>
<div>
<button onclick="ReDoS.GUI.testmatch( '*',null);return false;">test all .match()</button>
<button onclick="ReDoS.GUI.testreplace('*',null);return false;">test all .replace()</button>
<span title="known problems: FF2, FF3, Opera10, Camino, Sunrise1.8, Chrome, IE, ...">
  <b>Warning: </b>using buttons may hang your browser!
</span><br/>
<span class="s" id="mcount">.</span>
<span class="s" id="rcount">.</span>
</div>
<br/>
<div id="result"></div>
</body></html>