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

more validation for containerName and blobKey to avoid access escape #203

Merged
merged 3 commits into from
May 6, 2024

Conversation

jixinchi
Copy link
Contributor

@jixinchi jixinchi commented Apr 3, 2024

No description provided.

@nacx nacx requested a review from gaul April 3, 2024 10:25
@@ -38,6 +38,8 @@ public void validate(String name) throws IllegalArgumentException {
//blobkey cannot start with / (or \ in Windows) character
if (name.startsWith("\\") || name.startsWith("/"))
throw new IllegalArgumentException("Blob key '" + name + "' cannot start with \\ or /");
if (name.contains("../"))
throw new IllegalArgumentException("Blob key '" + name + "' cannot contains ../");
Copy link
Member

Choose a reason for hiding this comment

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

super nit

Suggested change
throw new IllegalArgumentException("Blob key '" + name + "' cannot contains ../");
throw new IllegalArgumentException("Blob key '" + name + "' cannot contain ../");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@gaul gaul left a comment

Choose a reason for hiding this comment

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

Please add some unit test that exercises this logic.

@@ -38,6 +38,8 @@ public void validate(String name) throws IllegalArgumentException {
//blobkey cannot start with / (or \ in Windows) character
if (name.startsWith("\\") || name.startsWith("/"))
throw new IllegalArgumentException("Blob key '" + name + "' cannot start with \\ or /");
if (name.contains("../"))
throw new IllegalArgumentException("Blob key '" + name + "' cannot contain ../");
Copy link
Member

Choose a reason for hiding this comment

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

Why is this different than the container name validator? For robustness should this tokenize the path via / then check each component to see if one contains . or ..? This would allow keys like ..foo to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think ..foo should be allowed. I tried several object storage services, such as gcloud and aliyun oss, they all allow ..foo as object key.

@@ -691,6 +698,8 @@ public BlobAccess getBlobAccess(String containerName, String blobName) {

@Override
public void setBlobAccess(String container, String name, BlobAccess access) {
filesystemContainerNameValidator.validate(container);
filesystemBlobKeyValidator.validate(name);
Copy link
Member

Choose a reason for hiding this comment

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

Should this also apply to getBlobAccess, putBlob, and removeBlob? getBlobKeysInsideContainer too I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These methods have been applied by the validators. I just added some missing ones.

@jixinchi
Copy link
Contributor Author

jixinchi commented May 6, 2024

@gaul Could you please review the new commits?

@gaul gaul merged commit 6670c55 into apache:master May 6, 2024
1 check passed
@gaul
Copy link
Member

gaul commented May 6, 2024

Thank you for your contribution @jixinchi!

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.

3 participants