@@ -7,7 +7,18 @@ import { logger } from "../../utils/logger";
7
7
import { prisma } from "../client" ;
8
8
import { updateConfiguration } from "./updateConfiguration" ;
9
9
10
- interface Config extends Configuration {
10
+ interface Config
11
+ extends Omit <
12
+ Configuration ,
13
+ | "awsAccessKeyId"
14
+ | "awsSecretAccessKey"
15
+ | "awsRegion"
16
+ | "gcpApplicationProjectId"
17
+ | "gcpKmsLocationId"
18
+ | "gcpKmsKeyRingId"
19
+ | "gcpApplicationCredentialEmail"
20
+ | "gcpApplicationCredentialPrivateKey"
21
+ > {
11
22
walletConfiguration :
12
23
| {
13
24
type : WalletType . local ;
@@ -29,90 +40,103 @@ interface Config extends Configuration {
29
40
}
30
41
31
42
const withWalletConfig = async ( config : Configuration ) : Promise < Config > => {
43
+ // We destructure the config to omit wallet related fields to prevent direct access
44
+ const {
45
+ awsAccessKeyId,
46
+ awsSecretAccessKey,
47
+ awsRegion,
48
+ gcpApplicationProjectId,
49
+ gcpKmsLocationId,
50
+ gcpKmsKeyRingId,
51
+ gcpApplicationCredentialEmail,
52
+ gcpApplicationCredentialPrivateKey,
53
+ ...restConfig
54
+ } = config ;
55
+
32
56
// TODO: Remove backwards compatibility with next breaking change
33
- if ( config . awsAccessKeyId && config . awsSecretAccessKey && config . awsRegion ) {
57
+ if ( awsAccessKeyId && awsSecretAccessKey && awsRegion ) {
34
58
// First try to load the aws secret using the encryption password
35
- let awsSecretAccessKey = decrypt (
36
- config . awsSecretAccessKey ,
59
+ let decryptedSecretAccessKey = decrypt (
60
+ awsSecretAccessKey ,
37
61
env . ENCRYPTION_PASSWORD ,
38
62
) ;
39
63
40
64
// If that fails, try to load the aws secret using the thirdweb api secret key
41
65
if ( ! awsSecretAccessKey ) {
42
- awsSecretAccessKey = decrypt (
43
- config . awsSecretAccessKey ,
66
+ decryptedSecretAccessKey = decrypt (
67
+ awsSecretAccessKey ,
44
68
env . THIRDWEB_API_SECRET_KEY ,
45
69
) ;
46
70
47
71
// If that succeeds, update the configuration with the encryption password instead
48
- if ( awsSecretAccessKey ) {
72
+ if ( decryptedSecretAccessKey ) {
49
73
logger . worker . info (
50
74
`[Encryption] Updating awsSecretAccessKey to use ENCRYPTION_PASSWORD` ,
51
75
) ;
52
76
await updateConfiguration ( {
53
- awsSecretAccessKey,
77
+ awsSecretAccessKey : decryptedSecretAccessKey ,
54
78
} ) ;
55
79
}
56
80
}
57
81
58
82
return {
59
- ...config ,
83
+ ...restConfig ,
60
84
walletConfiguration : {
61
85
type : WalletType . awsKms ,
62
- awsRegion : config . awsRegion ,
63
- awsAccessKeyId : config . awsAccessKeyId ,
64
- awsSecretAccessKey,
86
+ awsRegion,
87
+ awsAccessKeyId,
88
+ awsSecretAccessKey : decryptedSecretAccessKey ,
65
89
} ,
66
90
} ;
67
91
}
68
92
69
93
// TODO: Remove backwards compatibility with next breaking change
70
94
if (
71
- config . gcpApplicationProjectId &&
72
- config . gcpKmsLocationId &&
73
- config . gcpKmsKeyRingId &&
74
- config . gcpApplicationCredentialEmail &&
75
- config . gcpApplicationCredentialPrivateKey
95
+ gcpApplicationProjectId &&
96
+ gcpKmsLocationId &&
97
+ gcpKmsKeyRingId &&
98
+ gcpApplicationCredentialEmail &&
99
+ gcpApplicationCredentialPrivateKey
76
100
) {
77
101
// First try to load the gcp secret using the encryption password
78
- let gcpApplicationCredentialPrivateKey = decrypt (
79
- config . gcpApplicationCredentialPrivateKey ,
102
+ let decryptedGcpKey = decrypt (
103
+ gcpApplicationCredentialPrivateKey ,
80
104
env . ENCRYPTION_PASSWORD ,
81
105
) ;
82
106
83
107
// If that fails, try to load the gcp secret using the thirdweb api secret key
84
108
if ( ! gcpApplicationCredentialPrivateKey ) {
85
- gcpApplicationCredentialPrivateKey = decrypt (
86
- config . gcpApplicationCredentialPrivateKey ,
109
+ decryptedGcpKey = decrypt (
110
+ gcpApplicationCredentialPrivateKey ,
87
111
env . THIRDWEB_API_SECRET_KEY ,
88
112
) ;
89
113
90
114
// If that succeeds, update the configuration with the encryption password instead
91
- if ( gcpApplicationCredentialPrivateKey ) {
115
+ if ( decryptedGcpKey ) {
92
116
logger . worker . info (
93
117
`[Encryption] Updating gcpApplicationCredentialPrivateKey to use ENCRYPTION_PASSWORD` ,
94
118
) ;
95
119
await updateConfiguration ( {
96
- gcpApplicationCredentialPrivateKey,
120
+ gcpApplicationCredentialPrivateKey : decryptedGcpKey ,
97
121
} ) ;
98
122
}
99
123
}
100
124
101
125
return {
102
- ...config ,
126
+ ...restConfig ,
103
127
walletConfiguration : {
104
128
type : WalletType . gcpKms ,
105
- gcpApplicationProjectId : config . gcpApplicationProjectId ,
106
- gcpKmsLocationId : config . gcpKmsLocationId ,
107
- gcpKmsKeyRingId : config . gcpKmsKeyRingId ,
108
- gcpApplicationCredentialEmail : config . gcpApplicationCredentialEmail ,
109
- gcpApplicationCredentialPrivateKey,
129
+ gcpApplicationProjectId,
130
+ gcpKmsLocationId,
131
+ gcpKmsKeyRingId,
132
+ gcpApplicationCredentialEmail,
133
+ gcpApplicationCredentialPrivateKey : decryptedGcpKey ,
110
134
} ,
111
135
} ;
112
136
}
113
137
114
138
return {
115
- ...config ,
139
+ ...restConfig ,
116
140
walletConfiguration : {
117
141
type : WalletType . local ,
118
142
} ,
0 commit comments