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

[JENKINS-56931] handle absolute paths correctly when unzipping #3425

Merged
merged 2 commits into from
Apr 8, 2019

Conversation

aviadatsnyk
Copy link
Contributor

@aviadatsnyk aviadatsnyk commented May 6, 2018

When checking that an unzipped file does not break out of the target directory - this handle relative paths correctly, where the previous implementation might not. This should prevent a bug that might have been introduced in #3402. For example: if the target directory is ./the-dir and the unzipping happens in /a/b/c an archive with a file path /a/b/c/the-dir which should be legal, will throw an exception.

I don't know if this is even possible under jenkins, but it's a bug nonetheless.

See JENKINS-56931.

Proposed changelog entries

Submitter checklist

  • JIRA issue is well described
  • Changelog entry appropriate for the audience affected by the change (users or developer, depending on the change). Examples
    * Use the Internal: prefix if the change has no user-visible impact (API, test frameworks, etc.)
  • Appropriate autotests or explanation to why this change has no tests

Desired reviewers

@aviadatsnyk
Copy link
Contributor Author

I'm not sure which tests are failing - couldn't find any on the link, but a bunch of linux tests were skipped.

@oleg-nenashev
Copy link
Member

Test failure is unrelated, we have an infra issue after the weekly release: ERROR: No artifacts found that match the file pattern "**/*-rc15725.2d1a7693b618/*-rc15725.2d1a7693b618*".

@oleg-nenashev
Copy link
Member

@aviadatsnyk Could you please create a JIRA ticket for it. If 2.120 gets elected as LTS, we may need t backport it

@oleg-nenashev oleg-nenashev added the needs-jira-issue A JIRA issue should be created for this PR. It is usually needed for the LTS backporting process label May 7, 2018
@daniel-beck
Copy link
Member

@aviadatsnyk Don't you mean absolute paths?

@aviadatsnyk
Copy link
Contributor Author

@daniel-beck according to StackOverflow and getCanonicalPath docs I think we need canonical paths here, to avoid edge cases like /my/ok/path/to/zip and /my/also/../ok/path. That said, I haven't done much java programming lately, so might be missing something here.

@aviadatsnyk
Copy link
Contributor Author

@oleg-nenashev I'd be happy to open a JIRA, could you please point me to an example similar ticket or some guidlines? I wouldn't like to mess things up in JIRA, and I noticed y'all are very organized with it.

@daniel-beck
Copy link
Member

@aviadatsnyk Was more of a comment about the PR description. The paths you're concerned about here are absolute paths in the zip file that happen to end up within the destination dir -- or I don't understand what this does.

@aviadatsnyk aviadatsnyk changed the title handle relative paths correctly when unzipping handle absolute paths correctly when unzipping May 8, 2018
@aviadatsnyk
Copy link
Contributor Author

aviadatsnyk commented May 8, 2018

@daniel-beck you're right. fixed the PR title and the commit message.

When checking that an unzipped file does not break out of the target directory - this handles '..' in absolute paths correctly, where the previous implementation might not.
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

I completely missed updates in this PR, sorry. After some reviews, I believe this is a reasonable code quality improvement which we could merge. I will create a JIRA issue and update the changelog

CC @Wadeck @jeffret-b @jvz who might be interested to double-check

@oleg-nenashev oleg-nenashev self-assigned this Feb 8, 2019
Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

Copy link
Contributor

@jeffret-b jeffret-b left a comment

Choose a reason for hiding this comment

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

Looks good. It's good to get caught up on ones like this and get them merged in.

Copy link
Contributor

@Wadeck Wadeck left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @aviadatsnyk.

I would strongly appreciate a test demonstrating the things that are fixed with this PR.

I don't know if this is even possible under jenkins, but it's a bug nonetheless.

My point here is that a bug that is just hypothetical but not happening in reality, is not really a bug, right? If you can at least try to write a test to demonstrate what is fixed, would be nice.

If you can't make a "regular" test working there, perhaps you can try to just call the private method using reflection or marking the method as internal (no access modifier).

@batmat
Copy link
Member

batmat commented Apr 4, 2019

Test failures look like #3962, retriggering anew to see the PR build status updated at least.

@batmat batmat closed this Apr 4, 2019
@batmat batmat reopened this Apr 4, 2019
@aviadatsnyk
Copy link
Contributor Author

@Wadeck - this can totally happen in reality. All you need is a JAR for a plugin that is malicious, something like https://github.com/snyk/zip-slip-vulnerability/tree/master/archives

Testing this will probably be not trivial, since we'll need to look at the file system to see the difference.

@batmat
Copy link
Member

batmat commented Apr 7, 2019

Given the number of approvals, this seems ready for merge.

I would also have appreciated an additional test, but going to consider the majority of reviewers, many from the security team, as sufficient I think.

@batmat batmat added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Apr 7, 2019
@Wadeck
Copy link
Contributor

Wadeck commented Apr 8, 2019

since we'll need to look at the file system to see the difference

If it's the only thing that is not trivial, I think we can collaborate with you to create that test.

@batmat
Copy link
Member

batmat commented Apr 8, 2019

Failure seems related to infra, which was partly improved by #3962, retriggering given this was previously building fine the days before without any new change (and I don't believe changes on master touched this area).
image
image

@batmat batmat closed this Apr 8, 2019
@batmat batmat reopened this Apr 8, 2019
@batmat batmat self-requested a review April 8, 2019 09:40
@Wadeck Wadeck changed the title handle absolute paths correctly when unzipping [JENKINS-56931] handle absolute paths correctly when unzipping Apr 8, 2019
@Wadeck
Copy link
Contributor

Wadeck commented Apr 8, 2019

After looking at the code, the bug is not reachable from regular code. You need to provide a relative File but the method is always used with FilePath that are swallowing the ./ stuff. So from my PoV, this corrects a potential future bug, reducing pain for future developers!

I took the opportunity to add tests to cover this case but also the initial one you wrote.

Test name Result before 3402 After 3402 before 3425 after 3425
zipAbsolutePathHandledCorrectly_unix ✔️ ✔️
zipAbsolutePathHandledCorrectly_win ✔️ ✔️
zipRelativePathHandledCorrectly ✔️ ✔️ ✔️
zipRelativePathHandledCorrectly_oneUp ✔️ ✔️
zipTarget_regular ✔️ ✔️ ✔️
zipTarget_relative ✔️ ❌ (this bug) ✔️

Wadeck added a commit to aviadatsnyk/jenkins that referenced this pull request Apr 8, 2019
@Wadeck Wadeck removed the needs-jira-issue A JIRA issue should be created for this PR. It is usually needed for the LTS backporting process label Apr 8, 2019
@aviadatsnyk
Copy link
Contributor Author

thank you @Wadeck !

@batmat
Copy link
Member

batmat commented Apr 8, 2019

\o/ Thanks @Wadeck for the test addition. Thanks a lot @aviadatsnyk for the fix!

I guess we can now really say this is ready for merge. I'll merge this later today or tomorrow, if nobody objects or does it in the meantime.

Thanks everyone!

@batmat batmat merged commit 58dfce4 into jenkinsci:master Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants