Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Litemall
Commits
49ab94d0
Commit
49ab94d0
authored
Oct 16, 2018
by
Junling Bu
Browse files
fix[litemall-wx-api]: 修复文件路径中包含"../"带来的安全问题
parent
3313051c
Changes
1
Hide whitespace changes
Inline
Side-by-side
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxStorageController.java
View file @
49ab94d0
...
...
@@ -58,14 +58,17 @@ public class WxStorageController {
public
ResponseEntity
<
Resource
>
fetch
(
@PathVariable
String
key
)
{
LitemallStorage
litemallStorage
=
litemallStorageService
.
findByKey
(
key
);
if
(
key
==
null
)
{
ResponseEntity
.
notFound
();
return
ResponseEntity
.
notFound
().
build
();
}
if
(
key
.
contains
(
"../"
)){
return
ResponseEntity
.
badRequest
().
build
();
}
String
type
=
litemallStorage
.
getType
();
MediaType
mediaType
=
MediaType
.
parseMediaType
(
type
);
Resource
file
=
storageService
.
loadAsResource
(
key
);
if
(
file
==
null
)
{
ResponseEntity
.
notFound
();
return
ResponseEntity
.
notFound
()
.
build
()
;
}
return
ResponseEntity
.
ok
().
contentType
(
mediaType
).
body
(
file
);
}
...
...
@@ -74,14 +77,18 @@ public class WxStorageController {
public
ResponseEntity
<
Resource
>
download
(
@PathVariable
String
key
)
{
LitemallStorage
litemallStorage
=
litemallStorageService
.
findByKey
(
key
);
if
(
key
==
null
)
{
ResponseEntity
.
notFound
();
return
ResponseEntity
.
notFound
().
build
();
}
if
(
key
.
contains
(
"../"
)){
return
ResponseEntity
.
badRequest
().
build
();
}
String
type
=
litemallStorage
.
getType
();
MediaType
mediaType
=
MediaType
.
parseMediaType
(
type
);
Resource
file
=
storageService
.
loadAsResource
(
key
);
if
(
file
==
null
)
{
ResponseEntity
.
notFound
();
return
ResponseEntity
.
notFound
()
.
build
()
;
}
return
ResponseEntity
.
ok
().
contentType
(
mediaType
).
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=\""
+
file
.
getFilename
()
+
"\""
).
body
(
file
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment