mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Sanitize search input (#3591)
* Sanitize search input - Remove ASCII and unicode control characters * js linting * Simplified regex * Sanitize modal form fields also
This commit is contained in:
parent
12509203d6
commit
528da731f2
@ -1007,6 +1007,11 @@ function getFormFieldValue(name, field={}, options={}) {
|
|||||||
value = null;
|
value = null;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'string':
|
||||||
|
case 'url':
|
||||||
|
case 'email':
|
||||||
|
value = sanitizeInputString(el.val());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
value = el.val();
|
value = el.val();
|
||||||
break;
|
break;
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
makeIconButton,
|
makeIconButton,
|
||||||
makeProgressBar,
|
makeProgressBar,
|
||||||
renderLink,
|
renderLink,
|
||||||
|
sanitizeInputString,
|
||||||
select2Thumbnail,
|
select2Thumbnail,
|
||||||
setupNotesField,
|
setupNotesField,
|
||||||
thumbnailImage
|
thumbnailImage
|
||||||
@ -326,3 +327,24 @@ function setupNotesField(element, url, options={}) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sanitize a string provided by the user from an input field,
|
||||||
|
* e.g. data form or search box
|
||||||
|
*
|
||||||
|
* - Remove leading / trailing whitespace
|
||||||
|
* - Remove hidden control characters
|
||||||
|
*/
|
||||||
|
function sanitizeInputString(s, options={}) {
|
||||||
|
|
||||||
|
// Remove ASCII control characters
|
||||||
|
s = s.replace(/[\x01-\x1F]+/g, '');
|
||||||
|
|
||||||
|
// Remove non-printable characters
|
||||||
|
s = s.replace(/[^ -~]+/g, '');
|
||||||
|
|
||||||
|
s = s.trim();
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
@ -98,7 +98,9 @@ var searchQueries = [];
|
|||||||
|
|
||||||
function searchTextChanged(event) {
|
function searchTextChanged(event) {
|
||||||
|
|
||||||
searchText = $('#offcanvas-search').find('#search-input').val();
|
var text = $('#offcanvas-search').find('#search-input').val();
|
||||||
|
|
||||||
|
searchText = sanitizeInputString(text);
|
||||||
|
|
||||||
clearTimeout(searchInputTimer);
|
clearTimeout(searchInputTimer);
|
||||||
searchInputTimer = setTimeout(updateSearch, 250);
|
searchInputTimer = setTimeout(updateSearch, 250);
|
||||||
|
Loading…
Reference in New Issue
Block a user