Skip to content

Commit fea7852

Browse files
authored
Update URL secret generation to use Random.secure() (#2432)
1 parent 8366c61 commit fea7852

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.25.14
2+
3+
* Use secure random for url secrets.
4+
15
## 1.25.13
26

37
* Allow the latest version of `package:matcher`.

pkgs/test/lib/src/util/math.dart

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:convert';
56
import 'dart:math' as math;
67

7-
final _rand = math.Random();
8+
final _rand = math.Random.secure();
89

9-
/// Returns a random 32 character alphanumeric string ([a-zA-Z0-9]), which is
10-
/// suitable as a url secret.
11-
String randomUrlSecret() {
12-
var buffer = StringBuffer();
13-
while (buffer.length < 32) {
14-
buffer.write(_alphaChars[_rand.nextInt(_alphaChars.length)]);
15-
}
16-
return buffer.toString();
17-
}
18-
19-
const _alphaChars =
20-
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
10+
/// Returns a random 64 bit token suitable as a url secret.
11+
String randomUrlSecret() =>
12+
base64Url.encode(List.generate(8, (_) => _rand.nextInt(256)));

pkgs/test/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test
2-
version: 1.25.13
2+
version: 1.25.14
33
description: >-
44
A full featured library for writing and running Dart tests across platforms.
55
repository: https://github.com/dart-lang/test/tree/master/pkgs/test

0 commit comments

Comments
 (0)