Skip to content

Commit 7a4766c

Browse files
committed
Fix error message path
1 parent ce5f958 commit 7a4766c

2 files changed

Lines changed: 21 additions & 15 deletions

File tree

lib/VWF/Allow.pm

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use File::Spec;
1414

1515
use constant DSHIELD_BASE => 'https://secure.dshield.org/api/sources/attacks/100/';
1616

17-
our %blacklist_countries = (
17+
my %blacklist_countries = (
1818
'BY' => 1,
1919
'MD' => 1,
2020
'RU' => 1,
@@ -35,7 +35,7 @@ our %blacklist_countries = (
3535
'XH' => 1,
3636
);
3737

38-
our %blacklist_agents = (
38+
my %blacklist_agents = (
3939
'Barkrowler' => 'Barkrowler',
4040
'masscan' => 'Masscan',
4141
'WBSearchBot' => 'Warebay',
@@ -48,7 +48,7 @@ our %blacklist_agents = (
4848
'ZoominfoBot (zoominfobot at zoominfo dot com)' => 'zoominfobot',
4949
);
5050

51-
our %status;
51+
my %status;
5252

5353
my $STATUS_TTL = 300; # 5 minutes; keeps memory bounded and lets throttle windows expire
5454

@@ -139,13 +139,16 @@ sub allow {
139139
}
140140
};
141141
if($@) {
142-
# Genuine YAML/IO error from Data::Throttler — delete the corrupt DB and continue
143-
if($logger) {
144-
$logger->info("removing $db_file: $@");
145-
} elsif(ref($@) && $@->isa('Error')) {
146-
# Deliberate block (throttle) — re-throw so caller sees the denial
142+
if(ref($@) && $@->isa('Error')) {
143+
# Deliberate throttle block: re-throw so the caller sees the denial.
144+
# Do NOT unlink the DB here -- that would erase the throttle window.
147145
$@->throw();
148146
}
147+
# Genuine YAML/IO error from Data::Throttler -- remove the corrupt file
148+
# and fall through so this request is served (fail open).
149+
if($logger) {
150+
$logger->info("removing corrupt throttle DB $db_file: $@");
151+
}
149152
unlink($db_file);
150153
}
151154

@@ -242,7 +245,7 @@ sub allow {
242245
my $cache = $args{'cache'};
243246
if(!defined($cache)) {
244247
throw Error::Simple('Either cache or config must be given') unless($args{config});
245-
$cache = ::create_memory_cache(config => $args{'config'}, namespace => __PACKAGE__, logger => $logger);
248+
$cache = VWF::Utils::create_memory_cache(config => $args{'config'}, namespace => __PACKAGE__, logger => $logger);
246249
}
247250
if(defined($cache)) {
248251
my $cachecontent = $cache->get($today);

lib/VWF/Config.pm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,7 @@ sub new
142142
unless -d $ENV{'CONFIG_DIR'} && -r $ENV{'CONFIG_DIR'};
143143
@config_dirs = ($ENV{'CONFIG_DIR'});
144144
} else {
145-
if($params->{config_directory}) {
146-
throw Error::Simple("config_directory must be a string") if(ref($params->{config_directory}));
147-
throw Error::Simple("config_directory '$params->{config_directory}' does not exist")
148-
unless -d $params->{config_directory};
149-
push(@config_dirs, $params->{config_directory});
150-
}
145+
# Build the standard search path; caller's config_directory is prepended below
151146
@config_dirs = (
152147
File::Spec->catdir(
153148
$info->script_dir(),
@@ -176,6 +171,14 @@ sub new
176171
'conf'
177172
));
178173
}
174+
175+
# Prepend the caller-supplied directory so it takes highest precedence
176+
if($params->{config_directory}) {
177+
throw Error::Simple("config_directory must be a string") if ref($params->{config_directory});
178+
throw Error::Simple("config_directory '$params->{config_directory}' does not exist")
179+
unless -d $params->{config_directory};
180+
unshift @config_dirs, $params->{config_directory};
181+
}
179182
}
180183

181184
# Look for localised configurations

0 commit comments

Comments
 (0)