Skip to content

Commit 3ddb36f

Browse files
authored
fix(server): check env name regex for batch update (#1065)
1 parent 20f3f46 commit 3ddb36f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

server/src/application/dto/create-env.dto.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class CreateEnvironmentDto {
66
@IsNotEmpty()
77
@IsString()
88
@Length(1, 64)
9-
@Matches(/^[a-zA-Z_][a-zA-Z0-9_]*$/)
9+
@Matches(/^[a-zA-Z_][a-zA-Z0-9_]{1,64}$/)
1010
name: string
1111

1212
@ApiProperty()

server/src/application/environment.controller.ts

+13
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ export class EnvironmentVariableController {
4949
@Param('appid') appid: string,
5050
@Body() dto: CreateEnvironmentDto[],
5151
) {
52+
// check env name and value (since validation decorator not work if dto is array)
53+
for (const item of dto) {
54+
if (/^[a-zA-Z_][a-zA-Z0-9_]{1,64}$/g.test(item.name) === false) {
55+
return ResponseUtil.error(
56+
'name must match /^[a-zA-Z_][a-zA-Z0-9_]{1,64}$/ : ' + item.name,
57+
)
58+
}
59+
60+
if (item.value.length > 4096) {
61+
return ResponseUtil.error('value must less than 4096: ' + item.name)
62+
}
63+
}
64+
5265
// app secret can not missing or empty
5366
const secret = dto.find((item) => item.name === APPLICATION_SECRET_KEY)
5467
if (!secret || !secret.value) {

0 commit comments

Comments
 (0)