8000 SEAB-6173: Fix miscellaneous "fuzzing bugs" by svonworl · Pull Request #5862 · dockstore/dockstore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

SEAB-6173: Fix miscellaneous "fuzzing bugs" #5862

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

Merged
merged 9 commits into from
Apr 8, 2024

Conversation

svonworl
Copy link
Contributor
@svonworl svonworl commented Apr 4, 2024

Description
This PR fixes the bugs that were uncovered during fuzz testing by the requests listed in https://ucsc-cgl.atlassian.net/browse/SEAB-6173, with the exception of the api/containers/schema/514/published request, which resulted in more extensive changes and is fixed in PR #5860.

I added some inline PR comments that describe what was fixed, and how.

Note that the "NUL character" bug is not fixed: #5862 (comment)

Review Instructions
Try the requests that are described in the issue, and confirm that the responses make sense and are not 500 status/error codes.

Issue
https://ucsc-cgl.atlassian.net/browse/SEAB-6173

Security and Privacy

No concerns.

  • Security and Privacy assessed

e.g. Does this change...

  • Any user data we collect, or data location?
  • Access control, authentication or authorization?
  • Encryption features?

Please make sure that you've checked the following before submitting your pull request. Thanks!

  • Check that you pass the basic style checks and unit tests by running mvn clean install
  • Ensure that the PR targets the correct branch. Check the milestone or fix version of the ticket.
  • Follow the existing JPA patterns for queries, using named parameters, to avoid SQL injection
  • If you are changing dependencies, check the Snyk status check or the dashboard to ensure you are not introducing new high/critical vulnerabilities
  • Assume that inputs to the API can be malicious, and sanitize and/or check for Denial of Service type values, e.g., massive sizes
  • Do not serve user-uploaded binary images through the Dockstore API
  • Ensure that endpoints that only allow privileged access enforce that with the @RolesAllowed annotation
  • Do not create cookies, although this may change in the future
  • If this PR is for a user-facing feature, create and link a documentation ticket for this feature (usually in the same milestone as the linked issue). Style points if you create a documentation PR directly and link that instead.

@@ -330,7 +331,7 @@ private String getRSS() {
@ApiOperation(value = "Returns the file containing runner dependencies.", response = String.class)
public Response getRunnerDependencies(
@Parameter(name = "client_version", description = "The Dockstore client version (e.g. 1.13.0)", schema = @Schema(pattern = PipHelper.OPENAPI_SEM_VER_STRING))
@ApiParam(value = "The Dockstore client version (e.g. 1.13.0)") @QueryParam("client_version") String clientVersion,
@ApiParam(value = "The Dockstore client version (e.g. 1.13.0)") @NotNull @QueryParam("client_version") String clientVersion,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Require client_version

List<Workflow> workflows = workflowDAO.findAllByPath(path, false);
workflows.forEach(this::checkNotNullEntry);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check was not necessary, the returned list of workflows never contains null entries.

Copy link
Contributor

Choose a reason for hiding this comment

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

List<Workflow> workflows = workflowDAO.findAllByPath(path, false);
workflows.forEach(this::checkNotNullEntry);
checkNotNull(workflows, "Invalid repository path");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

findAllByPath returns null if the path is invalid (not the expected format).

workflows.forEach(this::checkNotNullEntry);
public List<Workflow> getAllPublishedWorkflowByPath(@Parameter(description = "repository path") @PathParam("repository") String path) {
List<Workflow> workflows = workflowDAO.findAllByPath(path, true);
checkNotNull(workflows, "Invalid repository path");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make this endpoint behave like the others when the path is invalid.

@Parameter(description = "Workflow id") @PathParam("workflowId") Long workflowId,
@QueryParam("tag") String tag,
@NotNull @QueryParam("language") DescriptorLanguage language) {
final FileType fileType = language.getFileType();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modernize parameter annotations and require language parameter.

registry = segments.get(0);
organization = segments.get(1);
name = segments.get(2);
toolName = segments.size() > SEGMENTS_IN_ID ? segments.get(SEGMENTS_IN_ID) : "";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check the tool id earlier, and refactor to improve clarity and remove a similar variable that could be accidentally used.

@Parameter(hidden = true, name = "user") @Auth Optional<User> user,
@Parameter(description = "Workflow id") @PathParam("workflowId") Long workflowId,
@QueryParam("tag") String tag,
@NotNull @QueryParam("language") DescriptorLanguage language) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change this parameter to an enum so that it works like similar endpoints.

Copy link
codecov bot commented Apr 4, 2024

Codecov Report

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

Project coverage is 74.52%. Comparing base (f03a1b4) to head (8f55ad4).

Files Patch % Lines
.../java/io/openapi/api/impl/ToolsApiServiceImpl.java 0.00% 11 Missing ⚠️
...in/java/io/dockstore/webservice/jdbi/EntryDAO.java 60.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             develop    #5862       +/-   ##
==============================================
+ Coverage      28.88%   74.52%   +45.63%     
- Complexity      2087     5276     +3189     
==============================================
  Files            369      369               
  Lines          19060    19063        +3     
  Branches        2025     2026        +1     
==============================================
+ Hits            5506    14207     +8701     
+ Misses         13123     3893     -9230     
- Partials         431      963      +532     
Flag Coverage Δ
bitbuckettests 27.06% <14.28%> (?)
integrationtests 58.54% <23.80%> (?)
languageparsingtests 11.01% <14.28%> (?)
localstacktests 21.58% <14.28%> (?)
toolintegrationtests 30.43% <14.28%> (?)
unit-tests_and_non-confidential-tests 28.88% <0.00%> (-0.01%) ⬇️
workflowintegrationtests 38.64% <33.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

results = include.stream().collect(Collectors.toMap(name -> name, name -> healthCheckRegistry.runHealthCheck(name)));
// Run each of the health checks, making sure that if a duplicate name is specified, the corresponding
// health check is only run once, to avoid the toMap Collector from throwing due to a duplicate key.
results = include.stream().distinct().collect(Collectors.toMap(name -> name, name -> healthCheckRegistry.runHealthCheck(name)));
Copy link
Contributor Author
@svonworl svonworl Apr 4, 2024

Choose a reason for hiding this comment

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

See code comment.

@svonworl
Copy link
Contributor Author
svonworl commented Apr 4, 2024

Ooops. forgot to note that the /api/categories?name=%00 request is not fixed. It happens because postgres doesn't like storing the NUL character (value 0) or accepting it in queries. The problem can be triggered on any endpoint that accepts a QueryParam and passes it on to the database, and there is no simple, straightforward fix (that I know of). So, we'll leave it as is for now.

Copy link
sonarqubecloud bot commented Apr 4, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
44.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@@ -791,9 +794,9 @@ public Tool publish(@ApiParam(hidden = true) @Parameter(hidden = true, name = "u
"containers"}, notes = "NO authentication", response = Tool.class, responseContainer = "List")
public List<Tool> allPublishedContainers(
@ApiParam(value = "Start index of paging. If not specified in the request, this will start at the beginning of the results.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Beyond the scope of this PR, but ApiParam is a Swagger annotation, and as such this description does not show up here: https://staging.dockstore.org/api/static/swagger-ui/index.html#/containers/allPublishedContainers

I'll create a ticket to more methodically go through this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, there's a ton of those. I fixed some, but not in the endpoints that I added the Max/Min to. Hopefully there's a quick way to automate it. It'd be nice to make the argument blocks more readable, too, maybe one argument per line?

@svonworl svonworl merged commit 7347da6 into develop Apr 8, 2024
@svonworl svonworl deleted the feature/seab-6173/invalid-credential-fixes branch April 8, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0