Skip to content

Commit 02caa37

Browse files
committed
fix(secure): fix upload file secure problem #1
1 parent c168c9e commit 02caa37

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

packages/app-server/src/config.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@ export default class Config {
4848
}
4949

5050
/**
51-
* the file system driver: 'local', 'gridfs'
51+
* the file system driver: 'localfs', 'gridfs'
5252
*/
53-
static get FILE_SYSTEM_DRIVER(): string {
54-
return process.env['FILE_SYSTEM_DRIVER'] ?? 'gridfs'
53+
static get FILE_SYSTEM_DRIVER(): 'gridfs' | 'localfs' {
54+
return process.env['FILE_SYSTEM_DRIVER'] as any ?? 'gridfs'
55+
}
56+
57+
/**
58+
* if enable the unauthorized upload operation in `public` bucket: 'on' | 'off'.
59+
* default is 'on'
60+
*/
61+
static get FILE_SYSTEM_ENABLE_UNAUTHORIZED_UPLOAD(): 'on' | 'off' {
62+
return process.env['FILE_SYSTEM_ENABLE_UNAUTHORIZED_UPLOAD'] as any ?? 'on'
5563
}
5664

5765
/**
@@ -72,8 +80,8 @@ export default class Config {
7280
/**
7381
* the logger level : 'fatal', 'error', 'warning', 'info', 'debug', 'trace'
7482
*/
75-
static get LOG_LEVEL(): string {
76-
return process.env['LOG_LEVEL'] ?? (this.isProd ? 'info' : 'debug')
83+
static get LOG_LEVEL(): 'fatal' | 'error' | 'warning' | 'info' | 'debug' | 'trace' {
84+
return process.env['LOG_LEVEL'] as any ?? (this.isProd ? 'info' : 'debug')
7785
}
7886

7987
/**
@@ -89,8 +97,8 @@ export default class Config {
8997
* - `debug` means that only logging for debug invokes
9098
* - `never` no logging any case
9199
*/
92-
static get ENABLE_CLOUD_FUNCTION_LOG(): string {
93-
return (process.env.ENABLE_CLOUD_FUNCTION_LOG ?? 'always')
100+
static get ENABLE_CLOUD_FUNCTION_LOG(): 'always' | 'debug' | 'never' {
101+
return (process.env.ENABLE_CLOUD_FUNCTION_LOG as any ?? 'always')
94102
}
95103

96104
/**

packages/devops-admin/src/views/database/files.vue

+8-11
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
</el-table-column>
5555
<el-table-column label="类型" align="center">
5656
<template slot-scope="{row}">
57-
<span v-if="row.contentType">{{ row.contentType }}</span>
58-
<span v-else>-</span>
57+
<span>{{ getContentType(row) }}</span>
5958
</template>
6059
</el-table-column>
6160
<el-table-column label="更新时间" width="180" align="center">
@@ -209,8 +208,7 @@ export default {
209208
getFileUrl(file) {
210209
assert(file && file.filename, 'invalid file or filename')
211210
const base_url = process.env.VUE_APP_BASE_API_APP + '/file'
212-
const bucket = this.bucket
213-
const file_url = `${base_url}/${bucket}/${file.filename}`
211+
const file_url = `${base_url}/${this.bucket}/${file.filename}`
214212
if (this.bucket === 'public') {
215213
return file_url
216214
}
@@ -221,21 +219,20 @@ export default {
221219
getUploadUrl() {
222220
assert(this.bucket, 'empty bucket name got')
223221
const base_url = process.env.VUE_APP_BASE_API_APP + '/file'
224-
const bucket = this.bucket
225-
const file_url = `${base_url}/upload/${bucket}`
226-
if (this.bucket === 'public') {
227-
return file_url
228-
}
222+
const file_url = `${base_url}/upload/${this.bucket}`
229223
const token = getFileToken()
230224
return file_url + `?token=${token}`
231225
},
226+
getContentType(row) {
227+
return row?.metadata?.contentType ?? row?.contentType ?? 'unknown'
228+
},
232229
// 判断是否为图片类型
233230
isImage(row) {
234-
return row?.contentType?.startsWith('image/')
231+
return this.getContentType(row)?.startsWith('image/')
235232
},
236233
// 判断是否为视频类型
237234
isVideo(row) {
238-
return row?.contentType?.startsWith('video/')
235+
return this.getContentType(row).startsWith('video/')
239236
},
240237
// 获取文件显示大小
241238
getFileSize(file) {

0 commit comments

Comments
 (0)