-
Notifications
You must be signed in to change notification settings - Fork 255
Restrict gltf URIs to relative paths by default; add --allowAbsolute
as fallback to insecure behavior.
#674
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
Conversation
…e` as fallback to insecure behavior.
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 tried this out with the example glTF that was given in the issue (adjusted for Windows).
And it seems to resolve the issue: With the current main
state, it inlines some password.txt
into the target glTF. With the state from this branch, it bails out with the error.
Specifying --allow-absolute
restores the original behavior.
There's a minor inconsistency here:
- The error message calls it
allowAbsolute
- The command line help calls it
allow-absolute
Both seem to work (which is likely a side-effect of the yargs argument parser). But it may be better to (not rely on that and) use consistent style in the help and error message. I'd vote for allowAbsolute
, which is more consistent with the existing flags (like separateTextures
etc).
The allowAbsolute
flag is also not mentioned in the "Command-Line Flags" in the README.md. It should be added there as well.
I also tried to "break" it 😈 , with obscure combinations of input directories and URL paths. But it seems like the combination of path.relative
and startsWith("..")
catches all cases 🤞
And it may, in fact, catch too many cases: When the URI is something like
"uri": "../password.txt"
then this is not an absolute URI, but still rejected here. Such URLs are actually legitimate, and not uncommon. They are often used to refer to some common ../texture.png
or ../animation.bin
that is used by multiple glTFs.
This might not be an issue here: The default behavior should be safe, and gltf-pipeline
should not mess around in the file system. If someone has such a file, the allowAbsolute
can be used to process it anyway.
EDIT: Conversely, using an absolute path like
"uri": "file:///C:/tmp/password.txt"
in a file like c:/tmp/example.gltf
does not complain. It's an absolute path, but resolved to a relative one.
This fix currently focusses on the command line usage. If the goal was also to apply this when this is used as a library (where the resourceDirectory
might not be present), I'll have to run more tests.
I assume that this was not the intention for now.
Possibly somehow related to this:
- Files with external
http://
uri refererences can't be procesed with gltf-pipeline #666 - We considered to create some sort of abstraction for the file access. (This doesn't seem to be tracked here, but came up e.g. in
glTF model references separate files but no resourceDirectory is supplied
Error when upgrading legacy 3d tiles 3d-tiles-tools#109 ). Instead of juggling with paths, thegltf-pipeline
should probably receive some function that receives astring
and returns aBuffer
, and that can resolve either against the file system, or against ... anything else. However, given that the future ofgltf-pipeline
is not clear, no effort went into that yet.
A less aggressive check might be
You're correct; I wasn't thinking about the programmatic case at all. It seems to me that, going forward, we should recommend to the developer to either:
Barring that, to handle existing code that might not already follow those recommendations, the safest change would be to treat
Naming the critical field |
--allow-absolute
as fallback to insecure behavior.--allowAbsolute
as fallback to insecure behavior.
The first review pass contained a few "nitpicks" that have been resolved now. Beyond that: The primary purpose is to get rid of the "file injection". And once we got gid of that, the PR should be ready to go. Any effort beyond the "least effort fix" here would be hard to justify, in view of #670 . So I do not want to hold up this PR. We should get this fix in soon, and not go overboard. But for completeness, I still want to emphasize how far one could go when reviewing this from the perspective of a pedantic nerd, in terms of functionality and sustainability:
Back to getting this merged: There currently is a test failure on Windows. The If desired, I can try to allocate some time to investigate this and create a fix. (I might have a hard time resisting the urge to throw in some other cleanups with that, but I can try...) An aside: I just opened CesiumGS/3d-tiles-tools#184 - this LFI might also be an issue for the 3D Tiles Tools. |
I'm gonna be bold here and say both of those are correct behavior - though, The "uri" field is not an OS path; it's a URI. We would not expect a strongly non-URI thing like an absolute Windows path to be at all well-behaved. We also would not expect a lightly non-URI thing like an absolute POSIX path to be perfectly well-behaved - the semantics are similar, but POSIX paths don't need escaped like URIs do. Meanwhile, the spec only mandates relative URIs and data URLs. The fact we're allowing absolute URIs at all is allowed by the spec ("Client implementations MAY optionally support additional URI components. For example ...
*blink* I had to read that a few times before I understood what you meant; I honestly did not notice those weren't the
Understood, and agreed. Wasn't really suggesting it for this PR; just musing on the asides you listed... though...
...is exactly the case for planning to switch to a glTF deals in URIs, so it makes sense to work in that space as much as possible, particularly when doing path arithmetic. This project may never get a chance to get to it, but all the same. |
Maybe I buried that in that wall of text: Of course a "URI" like This is caused by the
then it does use the So maybe this point is/was just a side-effect from creating the specs. (As I said in the initial review: I might have to think through further cases for the library usage. Given that there are two "flavors" for a URI to count as "abolute" - namely, via the leading
But nitpickers could then complain about the missing test case for the leading |
Oh! Yeah. Didn't think about that for the test case (I mostly dev inside WSL). I'll adjust. |
With the latest state, the tests are passing on Windows as well. (And I also checked whether the actual issue is still resolved. Although I think that the last changes mainly revolved around the specs (and cleanups like removing that So I think this is ready to merge. (I'm not sure wheher I'm supposed to do this, or whether there is someone who counts more as an "active maintainer". In doubt, I'll just hit 'Merge' soon, assuming that I'm not stepping on anyone's toes...) |
Fixed a security issue (with the option to retain the original behavior). Added documentation. Removed legacy code. Added specs. I don't see why anyone would not want to merge this. |
Reference implementation for #673.
readFile
fail by default for files outside ofresourceDirectory
--allowAbsolute
flag /.allowAbsolute
option to disable this failure, and to emit a warning on the CLI about insecure gltf buffer URIs.resourceDirectory
is undefined and the gltf references an absolute path, but otherwise continues normally.