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

fix #11625: sanitize invalidly named FS paths #2909

Merged
merged 6 commits into from
Aug 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/blitz/resources/omero/Repositories.ice
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ module omero {
* returned which can be watched for knowing when the server-side import
* is complete.
*
* Client paths set in the fileset entries must /-separate their components.
*
* Once the upload is complete, the [ImportProcess] must be closed.
* Once [omero::cmd::Handle::getResponse] returns a non-null value, the
* handle instance can and must be closed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import ome.model.meta.Experimenter;
import ome.services.blitz.gateway.services.util.ServiceUtilities;
import ome.services.blitz.repo.path.ClientFilePathTransformer;
import ome.services.blitz.repo.path.FilePathNamingValidator;
import ome.services.blitz.repo.path.FilePathRestrictionInstance;
import ome.services.blitz.repo.path.FsFile;
import ome.services.blitz.repo.path.MakeNextDirectory;
Expand Down Expand Up @@ -140,9 +139,6 @@ public String apply(String from) {
Joiner.on(',').join(Collections2.transform(ChecksumAlgorithmMapper.getAllChecksumAlgorithms(),
ChecksumAlgorithmMapper.CHECKSUM_ALGORITHM_NAMER));

/* checks that FS file paths are legally named for the underlying file system */
private final FilePathNamingValidator filePathNamingValidator;

/* template paths: matches any special expansion term */
private static final Pattern TEMPLATE_TERM = Pattern.compile("%([a-zA-Z]+)(:([^%/]+))?%");

Expand Down Expand Up @@ -191,7 +187,6 @@ public ManagedRepositoryI(String template, RepositoryDao dao,
}

this.processes = processes;
this.filePathNamingValidator = new FilePathNamingValidator(this.filePathRestrictions);
this.rootSessionUuid = rootSessionUuid;
this.userGroupId = roles.getUserGroupId();
log.info("Repository template: " + template);
Expand Down Expand Up @@ -1331,11 +1326,13 @@ protected ImportLocation suggestImportPaths(FsFile relPath, FsFile basePath, Lis
basePath = trimmedPaths.basePath;
paths = trimmedPaths.fullPaths;

// validate paths
this.filePathNamingValidator.validateFilePathNaming(relPath);
this.filePathNamingValidator.validateFilePathNaming(basePath);
for (final FsFile path : paths) {
this.filePathNamingValidator.validateFilePathNaming(path);
// sanitize paths (should already be sanitary; could introduce conflicts)
final Function<String, String> sanitizer = serverPaths.getPathSanitizer();
relPath = relPath.transform(sanitizer);
basePath = basePath.transform(sanitizer);
int index = paths.size();
while (--index >= 0) {
paths.set(index, paths.get(index).transform(sanitizer));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I wondered if there was some nice Guava way to transform the elements of a collection (map (map f) ...) but I don't easily see one.


// Static elements which will be re-used throughout
Expand Down