Skip to content

Commit 706d114

Browse files
authored
Bug 1497487 - Backport bug 767623 to BMO: Use HMAC to generate tokens and sensitive graph filenames
1 parent 871fc7d commit 706d114

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

Bugzilla/Token.pm

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use Bugzilla::User;
2020
use Date::Format;
2121
use Date::Parse;
2222
use File::Basename;
23-
use Digest::MD5 qw(md5_hex);
2423
use Digest::SHA qw(hmac_sha256_base64);
2524
use Encode;
2625
use JSON qw(encode_json decode_json);
@@ -254,15 +253,15 @@ sub issue_hash_token {
254253
my $user_id = Bugzilla->user->id || remote_ip();
255254

256255
# The concatenated string is of the form
257-
# token creation time + site-wide secret + user ID (either ID or remote IP) + data
258-
my @args = ($time, Bugzilla->localconfig->{'site_wide_secret'}, $user_id, @$data);
256+
# token creation time + user ID (either ID or remote IP) + data
257+
my @args = ($time, $user_id, @$data);
259258

260259
my $token = join('*', @args);
261-
# Wide characters cause md5_hex() to die.
262-
if (Bugzilla->params->{'utf8'}) {
263-
utf8::encode($token) if utf8::is_utf8($token);
264-
}
265-
$token = md5_hex($token);
260+
# $token needs to be a byte string.
261+
utf8::encode($token);
262+
$token = hmac_sha256_base64($token, Bugzilla->localconfig->{'site_wide_secret'});
263+
$token =~ s/\+/-/g;
264+
$token =~ s/\//_/g;
266265

267266
# Prepend the token creation time, unencrypted, so that the token
268267
# lifetime can be validated.

reports.cgi

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use Bugzilla::Error;
1919
use Bugzilla::Status;
2020

2121
use File::Basename;
22-
use Digest::MD5 qw(md5_hex);
22+
use Digest::SHA qw(hmac_sha256_base64);
2323

2424
# If we're using bug groups for products, we should apply those restrictions
2525
# to viewing reports, as well. Time to check the login in that case.
@@ -90,14 +90,12 @@ else {
9090
# Filenames must not be guessable as they can point to products
9191
# you are not allowed to see. Also, different projects can have
9292
# the same product names.
93-
my $key = Bugzilla->localconfig->{'site_wide_secret'};
9493
my $project = bz_locations()->{'project'} || '';
95-
my $image_file = join(':', ($key, $project, $prod_id, @datasets));
96-
# Wide characters cause md5_hex() to die.
97-
if (Bugzilla->params->{'utf8'}) {
98-
utf8::encode($image_file) if utf8::is_utf8($image_file);
99-
}
100-
$image_file = md5_hex($image_file) . '.png';
94+
my $image_file = join(':', ($project, $prod_id, @datasets));
95+
my $key = Bugzilla->localconfig->{'site_wide_secret'};
96+
$image_file = hmac_sha256_base64($image_file, $key) . '.png';
97+
$image_file =~ s/\+/-/g;
98+
$image_file =~ s/\//_/g;
10199
trick_taint($image_file);
102100

103101
if (! -e "$graph_dir/$image_file") {

0 commit comments

Comments
 (0)