-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Adds verification of the file name #18848
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
Open
andsel
wants to merge
10
commits into
elastic:main
Choose a base branch
from
andsel:fix/verify_name
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+113
−2
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cdf7b80
Adds verification of the file name
andsel 5aab49f
Reimplemented name_safe? to work both on Unix and Windows filesystems
andsel 0e69e4b
Switched from boolean method to verification method that thorw differ…
andsel fc75e3f
Implemented handling of symlinks into tgz
andsel c90f19f
Keep the pack installer support only for zip files
andsel 18be6d9
Moved test to verify symlink into GeoIP downloader, which is the one …
andsel cbbf6d9
Moved tar.gz test to the geoip downloader part and avoid to support s…
andsel cc001c4
Fix, explicit import of pathname and bad method refernce name in comment
andsel 5a56f8a
Potential fix for pull request finding
andsel 8095570
Potential fix for pull request finding
andsel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # GeoIP downloader spec fixtures | ||
|
|
||
| ## Recreating `sample_with_symlink.tgz` | ||
|
|
||
| This archive is the same as `sample.tgz` plus a symbolic link `GeoLite2-City-alias.mmdb` → `GeoLite2-City.mmdb` at the archive root. `LogStash::Util::Tar.extract` rejects symlink entries, so this fixture is only for specs that assert that behavior. Run from this directory (Unix/macOS): | ||
|
|
||
| ```bash | ||
| cd "$(dirname "$0")" # or: cd x-pack/spec/geoip_database_management/fixtures | ||
| rm -rf _symlink_build && mkdir _symlink_build && tar -xzf sample.tgz -C _symlink_build | ||
| ln -s GeoLite2-City.mmdb _symlink_build/GeoLite2-City-alias.mmdb | ||
| tar -czf sample_with_symlink.tgz -C _symlink_build . | ||
| rm -rf _symlink_build | ||
| ``` |
Binary file added
BIN
+702 Bytes
x-pack/spec/geoip_database_management/fixtures/sample_with_symlink.tgz
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Since we're already in here, it'd be nice to handle the symlink issue for safety. When I started reviewing this I saw the note about them and was forced to think through whether this was exploitable or not.
While we are not presently vulnerable--since we only write regular files or create directories--it would be nice to at least handle the case here explicitly.
If someone (or some agent) mistakenly added symlink support this would be defensive. Also, we can remove the note later in the file about symlinks not being covered. This is one less bit of security surface area future contributors would have to worry about.
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 think we could use the
symlink?method present inGem::Package::TarReader::Entryinstead of using magic numbers (https://github.com/ruby/rubygems/blob/bcc44695d6bb0915912e10cbb09283c1e242f1ff/lib/rubygems/package/tar_reader/entry.rb#L127).However, it doesn't cover the hardlink case.
It seems that also zip has
symlink?method we can leverage.Uh oh!
There was an error while loading. Please reload this page.
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.
From better investigation I found that
rubyzip(at the version we use and above) disabled to decompress symlinks for security reasons.Version
3.2.2apparently re-introduced symlink: rubyzip/rubyzip#531There 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.
Hmmm, I'm not nuts about magic numbers either, weird there's no hardlink option. What would you like to do here?
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.
Ah, I see you added the symlink check below. Looks like the lib only covers symlinks anyway, so I think this is good!