Skip to content

Commit 4ebdd1e

Browse files
code fixes
1 parent 696ea5f commit 4ebdd1e

File tree

7 files changed

+24
-10
lines changed

7 files changed

+24
-10
lines changed

.snyk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
exclude:
33
global:
44
- __mocks__/**
5+
- tests
56
- redisinsight/api/test/**
67
- "*.spec.ts"
78
- "*.spec.tsx"

redisinsight/api/config/default.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export default {
8181
excludeRoutes: [],
8282
excludeAuthRoutes: [],
8383
},
84+
encryption: {
85+
encryptionIV: process.env.RI_ENCRYPTION_IV || Buffer.alloc(16, 0),
86+
encryptionAlgorithm: process.env.RI_ENCRYPTION_ALGORYTHM || 'aes-256-cbc',
87+
},
8488
sockets: {
8589
cors: process.env.RI_SOCKETS_CORS ? process.env.RI_SOCKETS_CORS === 'true' : false,
8690
serveClient: process.env.RI_SOCKETS_SERVE_CLIENT ? process.env.RI_SOCKETS_SERVE_CLIENT === 'true' : false,

redisinsight/api/src/modules/cloud/user/cloud-user.api.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export class CloudUserApiService {
7474
throw new CloudApiUnauthorizedException();
7575
}
7676

77-
const decodedJwt = decode(session.accessToken);
77+
const { exp } = JSON.parse(Buffer.from(session.accessToken.split('.')[1], 'base64').toString());
7878

79-
const expiresIn = decodedJwt.exp * 1_000 - Date.now();
79+
const expiresIn = exp * 1_000 - Date.now();
8080

8181
if (expiresIn < cloudConfig.renewTokensBeforeExpire) {
8282
// need to renew

redisinsight/api/src/modules/encryption/strategies/key-encryption.strategy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
} from 'src/modules/encryption/exceptions';
1212
import config, { Config } from 'src/utils/config';
1313

14-
const ALGORITHM = 'aes-256-cbc';
1514
const HASH_ALGORITHM = 'sha256';
1615
const SERVER_CONFIG = config.get('server') as Config['server'];
16+
const ENCRYPTION_CONFIG = config.get('encryption') as Config['encryption'];
1717

1818
@Injectable()
1919
export class KeyEncryptionStrategy implements IEncryptionStrategy {
@@ -27,6 +27,10 @@ export class KeyEncryptionStrategy implements IEncryptionStrategy {
2727
this.key = SERVER_CONFIG.encryptionKey;
2828
}
2929

30+
private getCipherIV(): Buffer {
31+
return Buffer.from(ENCRYPTION_CONFIG.encryptionIV).slice(0, 16);
32+
}
33+
3034
/**
3135
* Will return existing cipher stored in-memory or
3236
* create new one using specified key and store it in-memory
@@ -55,7 +59,7 @@ export class KeyEncryptionStrategy implements IEncryptionStrategy {
5559
async encrypt(data: string): Promise<EncryptionResult> {
5660
const cipherKey = await this.getCipherKey();
5761
try {
58-
const cipher = createCipheriv(ALGORITHM, cipherKey, Buffer.alloc(16, 0));
62+
const cipher = createCipheriv(ENCRYPTION_CONFIG.encryptionAlgorithm, cipherKey, this.getCipherIV());
5963
let encrypted = cipher.update(data, 'utf8', 'hex');
6064
encrypted += cipher.final('hex');
6165

@@ -77,7 +81,7 @@ export class KeyEncryptionStrategy implements IEncryptionStrategy {
7781
const cipherKey = await this.getCipherKey();
7882

7983
try {
80-
const decipher = createDecipheriv(ALGORITHM, cipherKey, Buffer.alloc(16, 0));
84+
const decipher = createDecipheriv(ENCRYPTION_CONFIG.encryptionAlgorithm, cipherKey, this.getCipherIV());
8185
let decrypted = decipher.update(data, 'hex', 'utf8');
8286
decrypted += decipher.final('utf8');
8387
return decrypted;

redisinsight/api/src/modules/encryption/strategies/keytar-encryption.strategy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import config, { Config } from 'src/utils/config';
1313

1414
const SERVICE = 'redisinsight';
1515
const ACCOUNT = 'app';
16-
const ALGORITHM = 'aes-256-cbc';
1716
const SERVER_CONFIG = config.get('server') as Config['server'];
17+
const ENCRYPTION_CONFIG = config.get('encryption') as Config['encryption'];
1818

1919
@Injectable()
2020
export class KeytarEncryptionStrategy implements IEncryptionStrategy {
@@ -71,6 +71,10 @@ export class KeytarEncryptionStrategy implements IEncryptionStrategy {
7171
}
7272
}
7373

74+
private getCipherIV(): Buffer {
75+
return Buffer.from(ENCRYPTION_CONFIG.encryptionIV).slice(0, 16);
76+
}
77+
7478
/**
7579
* Get password from storage and create cipher key
7680
* Note: Will generate new password if it doesn't exists yet
@@ -107,7 +111,7 @@ export class KeytarEncryptionStrategy implements IEncryptionStrategy {
107111
async encrypt(data: string): Promise<EncryptionResult> {
108112
const cipherKey = await this.getCipherKey();
109113
try {
110-
const cipher = createCipheriv(ALGORITHM, cipherKey, Buffer.alloc(16, 0));
114+
const cipher = createCipheriv(ENCRYPTION_CONFIG.encryptionAlgorithm, cipherKey, this.getCipherIV());
111115
let encrypted = cipher.update(data, 'utf8', 'hex');
112116
encrypted += cipher.final('hex');
113117

@@ -128,7 +132,7 @@ export class KeytarEncryptionStrategy implements IEncryptionStrategy {
128132

129133
const cipherKey = await this.getCipherKey();
130134
try {
131-
const decipher = createDecipheriv(ALGORITHM, cipherKey, Buffer.alloc(16, 0));
135+
const decipher = createDecipheriv(ENCRYPTION_CONFIG.encryptionAlgorithm, cipherKey, this.getCipherIV());
132136
let decrypted = decipher.update(data, 'hex', 'utf8');
133137
decrypted += decipher.final('utf8');
134138
return decrypted;

redisinsight/api/src/modules/rdi/client/api.rdi.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ export class ApiRdiClient extends RdiClient {
172172
{ username: this.rdi.username, password: this.rdi.password },
173173
);
174174
const accessToken = response.data.access_token;
175-
const decodedJwt = decode(accessToken);
175+
const { exp } = JSON.parse(Buffer.from(accessToken.split('.')[1], 'base64').toString());
176176

177-
this.auth = { jwt: accessToken, exp: decodedJwt.exp };
177+
this.auth = { jwt: accessToken, exp };
178178
this.client.defaults.headers.common['Authorization'] = `Bearer ${accessToken}`;
179179
} catch (e) {
180180
throw wrapRdiPipelineError(e);

redisinsight/ui/src/pages/home/components/cluster-connection/cluster-connection-form/ClusterConnectionForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const fieldDisplayNames: Values = {
6161
host: 'Cluster Host',
6262
port: 'Cluster Port',
6363
username: 'Admin Username',
64+
// deepcode ignore NoHardcodedPasswords: <Not a passowrd but "password" field placeholder>
6465
password: 'Admin Password',
6566
}
6667

0 commit comments

Comments
 (0)