-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Fix can modify file which is not under resource path #15652
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -241,8 +221,8 @@ | |||
String.format("upload resource: %s file: %s failed.", name, file.getOriginalFilename())); | |||
} else | |||
ApiServerMetrics.recordApiResourceUploadSize(file.getSize()); | |||
log.info("Upload resource file complete, resourceName:{}, fileName:{}.", | |||
RegexUtils.escapeNRT(name), RegexUtils.escapeNRT(file.getOriginalFilename())); | |||
log.info("Upload resource file complete, resourceName:{}, fileName:{}.", RegexUtils.escapeNRT(name), |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
log.info("Upload resource file complete, resourceName:{}, fileName:{}.", | ||
RegexUtils.escapeNRT(name), RegexUtils.escapeNRT(file.getOriginalFilename())); | ||
log.info("Upload resource file complete, resourceName:{}, fileName:{}.", RegexUtils.escapeNRT(name), | ||
RegexUtils.escapeNRT(file.getOriginalFilename())); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
@@ -365,8 +341,8 @@ | |||
if (file != null) { | |||
// fail upload | |||
if (!upload(loginUser, fullName, file, type)) { | |||
log.error("Storage operation error, resourceName:{}, originFileName:{}.", | |||
name, RegexUtils.escapeNRT(file.getOriginalFilename())); | |||
log.error("Storage operation error, resourceName:{}, originFileName:{}.", name, |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
log.error("Storage operation error, resourceName:{}, originFileName:{}.", | ||
name, RegexUtils.escapeNRT(file.getOriginalFilename())); | ||
log.error("Storage operation error, resourceName:{}, originFileName:{}.", name, | ||
RegexUtils.escapeNRT(file.getOriginalFilename())); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
@@ -877,8 +822,8 @@ | |||
Result<Object> result = new Result<>(); | |||
putMsg(result, Status.SUCCESS); | |||
if (checkResourceExists(fullName)) { | |||
log.error("Resource with same name exists so can not create again, resourceType:{}, resourceName:{}.", | |||
type, RegexUtils.escapeNRT(fullName)); | |||
log.error("Resource with same name exists so can not create again, resourceType:{}, resourceName:{}.", type, |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
This log entry depends on a
user-provided value
Result<Object> result = new Result<>(); | ||
String localFilename = ""; | ||
try { | ||
localFilename = FileUtils.getUploadFilename(tenantCode, UUID.randomUUID().toString()); | ||
|
||
if (!FileUtils.writeContent2File(content, localFilename)) { | ||
// write file fail | ||
log.error("Write file error, fileName:{}, content:{}.", localFilename, | ||
RegexUtils.escapeNRT(content)); | ||
log.error("Write file error, fileName:{}, content:{}.", localFilename, RegexUtils.escapeNRT(content)); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
Result<Object> result = new Result<>(); | ||
String localFilename = ""; | ||
try { | ||
localFilename = FileUtils.getUploadFilename(tenantCode, UUID.randomUUID().toString()); | ||
|
||
if (!FileUtils.writeContent2File(content, localFilename)) { | ||
// write file fail | ||
log.error("Write file error, fileName:{}, content:{}.", localFilename, | ||
RegexUtils.escapeNRT(content)); | ||
log.error("Write file error, fileName:{}, content:{}.", localFilename, RegexUtils.escapeNRT(content)); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
This log entry depends on a
user-provided value
if (!storageOperate.exists(resourcePath)) { | ||
// create if tenant dir not exists | ||
storageOperate.createTenantDirIfNotExists(tenantCode); | ||
log.info("Create tenant dir because path {} does not exist, tenantCode:{}.", resourcePath, | ||
tenantCode); | ||
log.info("Create tenant dir because path {} does not exist, tenantCode:{}.", resourcePath, tenantCode); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
if (!storageOperate.exists(resourcePath)) { | ||
// create if tenant dir not exists | ||
storageOperate.createTenantDirIfNotExists(tenantCode); | ||
log.info("Create tenant dir because path {} does not exist, tenantCode:{}.", resourcePath, | ||
tenantCode); | ||
log.info("Create tenant dir because path {} does not exist, tenantCode:{}.", resourcePath, tenantCode); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
} | ||
if (storageOperate.exists(fullName)) { | ||
storageOperate.delete(fullName, false); | ||
} | ||
|
||
storageOperate.upload(tenantCode, localFilename, fullName, true, true); | ||
} catch (Exception e) { | ||
log.error("Upload content to storage error, tenantCode:{}, destFileName:{}.", tenantCode, localFilename, | ||
e); | ||
log.error("Upload content to storage error, tenantCode:{}, destFileName:{}.", tenantCode, localFilename, e); |
Check failure
Code scanning / CodeQL
Log Injection High
user-provided value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2168846
to
6a1d24c
Compare
6a1d24c
to
6ac4720
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #15652 +/- ##
============================================
- Coverage 38.57% 38.54% -0.03%
+ Complexity 4792 4783 -9
============================================
Files 1316 1316
Lines 45043 44968 -75
Branches 4823 4816 -7
============================================
- Hits 17374 17333 -41
+ Misses 25779 25755 -24
+ Partials 1890 1880 -10 ☔ View full report in Codecov by Sentry. |
Quality Gate failedFailed conditions |
String name, | ||
ResourceType type, | ||
MultipartFile file, | ||
public Result<Object> uploadResource(User loginUser, String name, ResourceType type, MultipartFile file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how the user can only modify the resource file under resource path. Could you please give some brief description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DS will throw exception when the user want to modify the system file which is not under resource path by update content API. This can help to protect the system.
The upload API will not be affected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall
Purpose of the pull request
Right now, user can use resource API to modify all files in the machine, this is not accepted.
This pr will fix this, user can only modify the resource file under resource path.
Brief change log
Verify this pull request
This pull request is code cleanup without any test coverage.
(or)
This pull request is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(or)
If your pull request contain incompatible change, you should also add it to
docs/docs/en/guide/upgrede/incompatible.md