SQL filter middleware

This commit is contained in:
Tobe O 2019-08-16 10:49:18 -04:00
parent 0995a77c3d
commit 7d3e4dc28b

View file

@ -9,6 +9,28 @@ LibInjectionScore sqlInjectionScore(String text) {
return LibInjectionScore(result[0] as bool, result[1] as String); return LibInjectionScore(result[0] as bool, result[1] as String);
} }
/// Uses `libinjection` to filter out possible SQL injections from the
/// query parameters ([RequestContext.queryParameters]).
///
/// Note: This is *destructive*, and modifies the query parameter map,
/// instead of returning new data.
bool sqliFilterQuery(RequestContext req, ResponseContext res) {
var out = <String, dynamic>{};
req.queryParameters.forEach((k, v) {
if (v is! String) {
out[k] = v;
} else {
var score = sqlInjectionScore(v as String);
if (!score.isInjection) {
out[k] = v;
}
}
});
req.queryParameters..clear()..addAll(out);
return true;
}
class LibInjectionScore { class LibInjectionScore {
final bool isInjection; final bool isInjection;
final String signature; final String signature;