Skip to content

Conversation

@ruanwenjun
Copy link
Member

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

  • Add path restriction in the resource update path.
  • Remove some unused code.

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

@ruanwenjun ruanwenjun self-assigned this Feb 28, 2024
@ruanwenjun ruanwenjun added 3.2.2 bug Something isn't working labels Feb 28, 2024
@github-actions github-actions bot added UI ui and front end related backend labels Feb 28, 2024
SbloodyS
SbloodyS previously approved these changes Feb 28, 2024
Copy link
Member

@SbloodyS SbloodyS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

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

This log entry depends on a [user-provided value](1).
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

This log entry depends on a [user-provided value](1).
putMsg(result, Status.SUCCESS);
} catch (Exception e) {
log.error(MessageFormat.format(" copy {0} -> {1} fail", originFullName, destHdfsFileName), e);
putMsg(result, Status.HDFS_COPY_FAIL);

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1).
} catch (Exception e) {
log.error(MessageFormat.format(" copy {0} -> {1} fail", originFullName, destHdfsFileName), e);
putMsg(result, Status.HDFS_COPY_FAIL);
throw new ServiceException(MessageFormat.format(

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1).

/**
* verify resource by full name or pid and type
*

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1). This log entry depends on a [user-provided value](2).
storageOperate.delete(fullName, false);
}

storageOperate.upload(tenantCode, localFilename, fullName, true, true);

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1).
storageOperate.delete(fullName, false);
}

storageOperate.upload(tenantCode, localFilename, fullName, true, true);

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1). This log entry depends on a [user-provided value](2).
putMsg(result, Status.SUCCESS);
return result;
}

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1).
putMsg(result, Status.SUCCESS);
return result;
}

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1).
public org.springframework.core.io.Resource downloadResource(User loginUser,
String fullName) {
public org.springframework.core.io.Resource downloadResource(User loginUser, String fullName) {
if (fullName.endsWith("/")) {

Check failure

Code scanning / CodeQL

Log Injection

This log entry depends on a [user-provided value](1).
Copy link
Member

@songjianet songjianet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Please remove referenced but unused variables.

@ruanwenjun ruanwenjun force-pushed the dev_wenjun_fixResourceAPI branch from 6a1d24c to 6ac4720 Compare February 29, 2024 02:45
@codecov-commenter
Copy link

codecov-commenter commented Feb 29, 2024

Codecov Report

Attention: Patch coverage is 47.22222% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 38.54%. Comparing base (3fda980) to head (671f88a).

❗ Current head 671f88a differs from pull request most recent head 6ac4720. Consider uploading reports for the commit 6ac4720 to get more accurate results

Files Patch % Lines
...heduler/api/service/impl/ResourcesServiceImpl.java 45.16% 17 Missing ⚠️
...nscheduler/api/controller/ResourcesController.java 60.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
46.2% Coverage on New Code (required ≥ 60%)

See analysis details on SonarCloud

String name,
ResourceType type,
MultipartFile file,
public Result<Object> uploadResource(User loginUser, String name, ResourceType type, MultipartFile file,
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

@caishunfeng caishunfeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

@caishunfeng caishunfeng added this to the 3.2.2 milestone Mar 1, 2024
@caishunfeng caishunfeng merged commit 88a8f06 into apache:dev Mar 1, 2024
@ruanwenjun ruanwenjun deleted the dev_wenjun_fixResourceAPI branch March 1, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.2.2 backend bug Something isn't working ready-to-merge UI ui and front end related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants