Skip to content

Commit 99be186

Browse files
committed
fix:codeql scan Security issue
1 parent bc88fa5 commit 99be186

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎app/src/main/java/com/tinyengine/it/task/DatabaseCleanupService.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class DatabaseCleanupService {
4444
private static final int HEX_NIBBLE_SHIFT = 4;
4545
private static final int HEX_NIBBLE_MASK = 0x0F;
4646
private static final int HEX_RADIX = 16;
47+
private static final SecureRandom EXECUTION_ID_RANDOM = new SecureRandom();
4748

4849
private final boolean cleanupEnabled;
4950
private final boolean useTruncate;
@@ -164,12 +165,11 @@ public void init() {
164165
* @return whitelist table names
165166
*/
166167
public List<String> getWhitelistTables() {
167-
return whitelistTables;
168+
return List.copyOf(whitelistTables);
168169
}
169170
private static String createExecutionId() {
170-
final SecureRandom random = new SecureRandom();
171171
final byte[] randomBytes = new byte[(EXEC_ID_LENGTH + 1) / 2];
172-
random.nextBytes(randomBytes);
172+
EXECUTION_ID_RANDOM.nextBytes(randomBytes);
173173
final StringBuilder identifier = new StringBuilder(randomBytes.length * 2);
174174
for (final byte randomByte : randomBytes) {
175175
identifier.append(

‎base/src/main/java/com/tinyengine/it/common/utils/SM4Utils.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class SM4Utils {
2424
private static final int IV_LENGTH_BYTES = 12;
2525
private static final int GCM_TAG_BITS = 128;
2626
private static final Base64Codec BASE64_CODEC = new Base64Codec();
27+
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
2728
static {
2829
Security.addProvider(new BouncyCastleProvider());
2930
}
@@ -49,8 +50,7 @@ public static String encrypt(final String apiKey, final String base64Key)
4950
throws GeneralSecurityException {
5051
final byte[] key = decodeKey(base64Key);
5152
final byte[] nonce = new byte[IV_LENGTH_BYTES];
52-
final SecureRandom random = new SecureRandom();
53-
random.nextBytes(nonce);
53+
SECURE_RANDOM.nextBytes(nonce);
5454

5555
final byte[] encrypted =
5656
doCipher(
@@ -123,7 +123,7 @@ private static final class KeyGeneratorService {
123123

124124
private KeyGeneratorService() throws GeneralSecurityException {
125125
generator = KeyGenerator.getInstance(ALGORITHM, "BC");
126-
generator.init(KEY_SIZE, new SecureRandom());
126+
generator.init(KEY_SIZE, SECURE_RANDOM);
127127
}
128128

129129
private byte[] generate() {

0 commit comments

Comments
 (0)