Skip to content
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

Add spotbugs and findsecbugs #185

Merged
merged 23 commits into from
Jun 15, 2020
Merged

Add spotbugs and findsecbugs #185

merged 23 commits into from
Jun 15, 2020

Conversation

jeffret-b
Copy link
Contributor

Add spotbugs and findsecbugs to Stapler as part of the long, ongoing effort to improve static code analysis. Stapler didn't even have standard spotbugs configured so this PR contains findings relating to general items and to security.

I took it to the Medium level (threshold), which seems to be about right for Stapler. This corrects or points out areas that might be of concern but isn't getting too esoteric.

I suppose there could be an argument that it isn't worthwhile to make these improvements in Stapler, because it isn't in active development. But, we sure seem to make a lot of changes to Stapler. I find that having spotbugs helps us to avoid introducing yet more issues, such as further instances of the public, non-final flag. And it brings better awareness to areas that could be an issue or where we need to tread carefully. Therefore, I believe it is better to introduce this analysis to help better support future work.

@jeffret-b
Copy link
Contributor Author

@jvz @daniel-beck @Wadeck

@jglick jglick added the chore label Jun 10, 2020
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

At least dropping of optional looks like a regression.

core/src/main/java/org/kohsuke/stapler/ForwardToView.java Outdated Show resolved Hide resolved
core/src/main/java/org/kohsuke/stapler/HttpRedirect.java Outdated Show resolved Hide resolved
core/src/main/java/org/kohsuke/stapler/ResponseImpl.java Outdated Show resolved Hide resolved
@@ -163,7 +163,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
return;
}
// remember URLs that we can serve. but don't remember error ones, as it might be unbounded
allowedResources.put(path,path);
allowedResources.putIfAbsent(path,path);
Copy link
Member

Choose a reason for hiding this comment

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

Why? We already checked !allowedResources.containsKey(path).

Cleaner would be to use ConcurrentSkipListSet and

if (allowedResources.add(path)) {
    // body…
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION : "This code contains a sequence of calls to a concurrent abstraction (such as a concurrent hash map). These calls will not be executed atomically."

The operations of !allowedResources.containsKey(path) and allowedResources.put(path,path) are not atomic when combined together so there is a potential multithreading issue in the middle of the sequence. The putIfAbsent is designed for that purpose.

But, a set is the correct semantic and we can change to ConcurrentSkipListSet.

pom.xml Outdated Show resolved Hide resolved
core/src/main/java/org/kohsuke/stapler/ForwardToView.java Outdated Show resolved Hide resolved
core/src/main/java/org/kohsuke/stapler/HttpRedirect.java Outdated Show resolved Hide resolved
core/src/main/java/org/kohsuke/stapler/ResponseImpl.java Outdated Show resolved Hide resolved
core/src/main/java/org/kohsuke/stapler/Stapler.java Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
@@ -163,7 +163,7 @@ public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
return;
}
// remember URLs that we can serve. but don't remember error ones, as it might be unbounded
allowedResources.put(path,path);
allowedResources.putIfAbsent(path,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.

AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION : "This code contains a sequence of calls to a concurrent abstraction (such as a concurrent hash map). These calls will not be executed atomically."

The operations of !allowedResources.containsKey(path) and allowedResources.put(path,path) are not atomic when combined together so there is a potential multithreading issue in the middle of the sequence. The putIfAbsent is designed for that purpose.

But, a set is the correct semantic and we can change to ConcurrentSkipListSet.

@jeffret-b jeffret-b changed the base branch from master to assets June 11, 2020 21:36
@jeffret-b jeffret-b changed the base branch from assets to master June 11, 2020 21:36
@jeffret-b
Copy link
Contributor Author

Not really sure what to do about these two new findings that were introduced in the recently merged PR introducing a new cache. @jglick any ideas?

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

two new findings

Details?

Comment on lines 87 to 88
if(destFile.exists() && !destFile.delete())
throw new IOException("Unable to delete "+destFile);
Copy link
Member

Choose a reason for hiding this comment

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

Could also use NIO here for better error reporting.

@jglick
Copy link
Member

jglick commented Jun 12, 2020

two new findings that were introduced in the recently merged PR introducing a new cache

Oh I see, new PATH_TRAVERSAL_INs to suppress (reading files from plugin code not users).

Comment on lines 28 to 32

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;

Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merge error.

core/src/main/java/org/kohsuke/stapler/HttpRedirect.java Outdated Show resolved Hide resolved
@jeffret-b
Copy link
Contributor Author

Builds fully again with another new suppression.

@Wadeck
Copy link
Contributor

Wadeck commented Jun 15, 2020

It seems the PR is already reviewed by two persons, so I do not plan to add another review.

@jeffret-b
Copy link
Contributor Author

Hmm ... it's passing locally. Let's see what a rebuild does.

@jeffret-b jeffret-b closed this Jun 15, 2020
@jeffret-b jeffret-b reopened this Jun 15, 2020
@jeffret-b
Copy link
Contributor Author

Build is passing now.

@jglick jglick merged commit b7f1b76 into jenkinsci:master Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants