Skip to content

Fix URI encoding in file listing and decoding to get file names - #471

Merged
dmitrizagidulin merged 3 commits into
masterfrom
tbl-uri-encoding
Jan 3, 2017
Merged

dmitrizagidulin merged 3 commits into
masterfrom
tbl-uri-encoding

Conversation

@timbl

@timbl timbl commented Dec 10, 2016

Copy link
Copy Markdown
Contributor

Also improve debug a little: truncate massive directory listings in the debug, add filename not found when 404 not found.

Designed to address #470

Comment thread lib/utils.js

function uriToFilename (uri, base) {
var filename = path.join(base, uri)
var decoded = uri.split('/').map(decodeURIComponent).join('/')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we're going to run into problems with this approach. What if the file (or container) was uploaded as already uri-encoded? Say, for example, it was uploaded as hello%20world.ttl? And exists on disk as hello%20world.ttl. If you then issue a GET on it and this method uriToFilename() is invoked, it will try and look for the filename hello world.ttl and not find it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is especially relevant given the recent PR #469, which url-encodes container names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When a file is uploaded, any filename is URI-encoded to form the URI.
If the file "hello world.ttl" exists then the resource "hello%20world.ttl" exists already too.
If there is a file on disk called "hello%20world.ttl" then there is corresponding LDP resource "hello%2520world.ttl"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reversible mapping. The file world is self-consistent. The URL world is self-consistent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In thinking about this, I realize we still have an open issue where we don't URI-encode file names on PUT. (Only container names). So it's still possible for people to try and create files with names that are illegal as far as the OS/filesystem is concerned.
If we fix this issue (and enforce URI-encoding of filenames on PUT and POST), then there is no need to uri-encode them on listing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A goal of this project is to be able to export existing files system users have. This means hex encoding things like space which are not allowed in URLs. A Windows or Mac Documents or Music folder should be be able to export into Solid in a useful way.

It is NOT a goal to be able to allow clients to put files with characters which are typically illegal in a file system, like say colon, slash, or vertical bar. I think we could return an error when a PUT or PATCH tries to do that (by hex encoding them in a URL). I don't see any value in allowing this characters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A goal of this project is to be able to export existing files system users have.

How would this export process work? The existing files would arrive on a Solid server via PUTs and POSTs, right? Which means their filenames would be safely encoded.

It is NOT a goal to be able to allow clients to put files with characters which are typically illegal in a file system

What would you like to see as the behavior when users/developers inevitably try to PUT or POST those kind of file names (illegal in file system)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe add * ? \
?

Or wait until the file system objects?

Example use case: I want to copy my entire Mac home folder into a solid server to sync it with other macs

@timbl

timbl commented Dec 14, 2016

Copy link
Copy Markdown
Contributor Author

In Mac, not much is illegal [] {} | all turn up as Chrome when you print off a page as PDF uses the windows title as a filename with very little adaptation!

http://stackoverflow.com/questions/1976007/what-characters-are-forbidden-in-windows-and-linux-directory-names

Should we be conservative to prevent badness down the line in file systems apps (like git, cross system backup, etc) or should web liberal so that in soemone'd complicated machup of different systems it does not mean that some in fact unnecessary constraint in node-solid-server end up breaking things which would otherwise work?

@dmitrizagidulin

Copy link
Copy Markdown
Contributor

I strongly believe we should be conservative, as far as accepting file name inputs via PUT, POST and PATCH, and URI-encode them. (to prevent all sorts of downstream problems, both with filesystem and with URIs).

Comment thread test/ldp.js
})
})
describe('listContainer', function () {
/*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you mind deleting the test, instead of commenting out?

Comment thread test/http.js
})
})

/* No, URLs are NOT ex-encoded to make filenames -- the other way around.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test should be changed to test for a 400 error response, per our conversation.

@dmitrizagidulin dmitrizagidulin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Had further conversations about this PR with Tim, I'm on board with this direction. Merging.

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.

2 participants