Skip to content

Commit

Permalink
Update URL secret generation to use Random.secure() (#2432)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemac53 authored Dec 19, 2024
1 parent 8366c61 commit fea7852
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
4 changes: 4 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.25.14

* Use secure random for url secrets.

## 1.25.13

* Allow the latest version of `package:matcher`.
Expand Down
18 changes: 5 additions & 13 deletions pkgs/test/lib/src/util/math.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:math' as math;

final _rand = math.Random();
final _rand = math.Random.secure();

/// Returns a random 32 character alphanumeric string ([a-zA-Z0-9]), which is
/// suitable as a url secret.
String randomUrlSecret() {
var buffer = StringBuffer();
while (buffer.length < 32) {
buffer.write(_alphaChars[_rand.nextInt(_alphaChars.length)]);
}
return buffer.toString();
}

const _alphaChars =
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
/// Returns a random 64 bit token suitable as a url secret.
String randomUrlSecret() =>
base64Url.encode(List.generate(8, (_) => _rand.nextInt(256)));
2 changes: 1 addition & 1 deletion pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test
version: 1.25.13
version: 1.25.14
description: >-
A full featured library for writing and running Dart tests across platforms.
repository: https://github.com/dart-lang/test/tree/master/pkgs/test
Expand Down

0 comments on commit fea7852

Please sign in to comment.