SQL filter middleware
This commit is contained in:
parent
0995a77c3d
commit
7d3e4dc28b
1 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue