Skip to content

Commit

Permalink
06b63b67ef3e2fc344d7b846a2316ba86030169d Fix: Security (CodeQL) - pot…
Browse files Browse the repository at this point in the history
…ential for `<script>` injection if done with multiple nesting

Fix: CodeQL warning - Multiple character replacement (wouldn't actually cause an issue due to the fact that the string was already limited to a single character, but for completeness, the regex would catch multiple characters now.
Fix: Use built in HTML striping function to read title from header - no security impact.
Fix: For state saved child row state, only escape `:` characters if not already escaped.

Sync to source repo @06b63b67ef3e2fc344d7b846a2316ba86030169d
  • Loading branch information
dtbuild committed Apr 9, 2024
1 parent bd375c8 commit a0d23af
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
],
"src-repo": "http://github.com/DataTables/DataTablesSrc",
"last-tag": "2.0.3",
"last-sync": "26a9c2f7f10d1b0f41009a6476b9784674c4767b"
"last-sync": "06b63b67ef3e2fc344d7b846a2316ba86030169d"
}
26 changes: 18 additions & 8 deletions js/dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,10 +1284,19 @@
};

// Replaceable function in api.util
var _stripHtml = function ( d ) {
return d
.replace( _re_html, '' ) // Complete tags
.replace(/<script/i, ''); // Safety for incomplete script tag
var _stripHtml = function (input) {
var previous;

input = input.replace(_re_html, ''); // Complete tags

// Safety for incomplete script tag - use do / while to ensure that
// we get all instances
do {
previous = input;
input = input.replace(/<script/i, '');
} while (input !== previous);

return previous;
};

// Replaceable function in api.util
Expand Down Expand Up @@ -3887,7 +3896,7 @@
}

if (! columnDef.sTitle && unique) {
columnDef.sTitle = cell.innerHTML.replace( /<.*?>/g, "" );
columnDef.sTitle = _stripHtml(cell.innerHTML);
columnDef.autoTitle = true;
}
}
Expand Down Expand Up @@ -4508,7 +4517,7 @@
word = '';
}

return word.replace('"', '');
return word.replace(/"/g, '');
} );

var match = not.length
Expand Down Expand Up @@ -7934,8 +7943,9 @@
{
if ( state && state.childRows ) {
api
.rows( state.childRows.map(function (id){
return id.replace(/:/g, '\\:')
.rows( state.childRows.map(function (id) {
// Escape any `:` characters from the row id, unless previously escaped
return id.replace(/(?<!\\):/g, '\\:');
}) )
.every( function () {
_fnCallbackFire( api.settings()[0], null, 'requestChild', [ this ] )
Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dataTables.min.mjs

Large diffs are not rendered by default.

26 changes: 18 additions & 8 deletions js/dataTables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,19 @@ var _removeEmpty = function ( a )
};

// Replaceable function in api.util
var _stripHtml = function ( d ) {
return d
.replace( _re_html, '' ) // Complete tags
.replace(/<script/i, ''); // Safety for incomplete script tag
var _stripHtml = function (input) {
var previous;

input = input.replace(_re_html, ''); // Complete tags

// Safety for incomplete script tag - use do / while to ensure that
// we get all instances
do {
previous = input;
input = input.replace(/<script/i, '');
} while (input !== previous);

return previous;
};

// Replaceable function in api.util
Expand Down Expand Up @@ -3834,7 +3843,7 @@ function _fnDetectHeader ( settings, thead, write )
}

if (! columnDef.sTitle && unique) {
columnDef.sTitle = cell.innerHTML.replace( /<.*?>/g, "" );
columnDef.sTitle = _stripHtml(cell.innerHTML);
columnDef.autoTitle = true;
}
}
Expand Down Expand Up @@ -4455,7 +4464,7 @@ function _fnFilterCreateSearch( search, inOpts )
word = '';
}

return word.replace('"', '');
return word.replace(/"/g, '');
} );

var match = not.length
Expand Down Expand Up @@ -7881,8 +7890,9 @@ var __details_state_load = function (api, state)
{
if ( state && state.childRows ) {
api
.rows( state.childRows.map(function (id){
return id.replace(/:/g, '\\:')
.rows( state.childRows.map(function (id) {
// Escape any `:` characters from the row id, unless previously escaped
return id.replace(/(?<!\\):/g, '\\:');
}) )
.every( function () {
_fnCallbackFire( api.settings()[0], null, 'requestChild', [ this ] )
Expand Down

0 comments on commit a0d23af

Please sign in to comment.