summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Config
diff options
context:
space:
mode:
authorMary Umoh <umohm12@gmail.com>2017-06-30 01:03:46 +0200
committerDylan William Hardison <dylan@hardison.net>2017-07-07 00:19:20 +0200
commit4c9f9a8c49e9f25096ee3b6982b197e9efa6dd60 (patch)
tree21fd41e87f0838321f4494f784fd94bc1f1b679f /Bugzilla/Config
parent662b0801c0e429b7d83c2ad6ed47a0293f10ff5e (diff)
downloadbugzilla-4c9f9a8c49e9f25096ee3b6982b197e9efa6dd60.tar.gz
bugzilla-4c9f9a8c49e9f25096ee3b6982b197e9efa6dd60.tar.xz
Bug 1355169 - Add rate-limiting to show_bug.cgi and rest.cgi
* fix mistake * Update * Updates * remove other file
Diffstat (limited to 'Bugzilla/Config')
-rw-r--r--Bugzilla/Config/Admin.pm33
1 files changed, 33 insertions, 0 deletions
diff --git a/Bugzilla/Config/Admin.pm b/Bugzilla/Config/Admin.pm
index 74748d3d8..5f10bfef3 100644
--- a/Bugzilla/Config/Admin.pm
+++ b/Bugzilla/Config/Admin.pm
@@ -12,6 +12,9 @@ use strict;
use warnings;
use Bugzilla::Config::Common;
+use JSON::XS qw(decode_json);
+use List::MoreUtils qw(all);
+use Scalar::Util qw(looks_like_number);
our $sortkey = 200;
@@ -44,6 +47,19 @@ sub get_param_list {
},
{
+ name => 'rate_limit_active',
+ type => 'b',
+ default => 1,
+ },
+
+ {
+ name => 'rate_limit_rules',
+ type => 'l',
+ default => '{"get_bug": [75, 60], "show_bug": [75, 60]}',
+ checker => \&check_rate_limit_rules,
+ },
+
+ {
name => 'log_user_requests',
type => 'b',
default => 0,
@@ -51,4 +67,21 @@ sub get_param_list {
return @param_list;
}
+sub check_rate_limit_rules {
+ my $rules = shift;
+
+ my $val = eval { decode_json($rules) };
+ return "failed to parse json" unless defined $val;
+ return "value is not HASH" unless ref $val && ref($val) eq 'HASH';
+ return "rules are invalid" unless all {
+ ref($_) eq 'ARRAY' && looks_like_number( $_->[0] ) && looks_like_number( $_->[1] )
+ } values %$val;
+
+ foreach my $required (qw( show_bug get_bug )) {
+ return "missing $required" unless exists $val->{$required};
+ }
+
+ return "";
+}
+
1;