don't follow symlinks or trust another user's file in FS.open - #1628
don't follow symlinks or trust another user's file in FS.open#1628netliomax25-code wants to merge 3 commits into
Conversation
|
Is this standard practice in other projects using cache files? Would it be easier to put the cache files somewhere else? |
|
Both fair questions.
The two aren't exclusive, and they're not the same size of change. I'm happy to convert this PR to a per-user cache directory, or leave it as the narrow fix and do the relocation separately. Whichever you'd rather carry. Validation on the branch: full suite green with and without atomicwrites installed (1315 tests), CI passing. |
|
any preference? |
|
I think we should consider doing both. The change from this PR on it's own is a good idea already. |
|
The current implementation does not refuse to open files that have incorrect permissions for reading, it just changes them. Is this intentional? And don't worry about cache invalidation, a new lark version is going to invalidate all caches anyway. |
The write path still tightens to 0600 rather than refusing, which seems right since it truncates and we own it. Added On the relocation: agreed, I'll keep this as the narrow fix and open the per-user cache directory as a separate PR. |
|
@erezsh I can't approve workflows AFAICT. |
|
@MegaIng I changed your role from “triage” to “write". Let me know if it still doesn't work. |
|
@erezsh Works, thank you. I am going to leave merging to you, but I think this PR is ready. |
|
Thanks, I haven't had time to look into it yet, but I'll do it soon. |
|
Fable had some comments, and at a glance they seem right. I would appreciate if you could address them.
(I'm not sure 2 is a bad thing, but worth keeping in mind.) |
cache=Truethe cache path is derived only from the grammar, the options and the version strings, so<tmpdir>/.lark_cache_<user>_<sha256>_3_12.tmpis predictable to anyone else with access to the temp directory.pickle.loadinlark.py:377before the sha256 line is compared on 378, and since that digest sits in the same file it is a cache key rather than an authenticity check, so the load is arbitrary code execution as whoever runs the parser.Sent the non-atomicwrites branch of
FS.openthrough anO_NOFOLLOWopen that also refuses a file it doesn't own and keeps the cache at 0600, which is roughly what the atomicwrites branch gets frommkstemptoday. A refused cache just falls through to the existing handlers, so the grammar is parsed normally. Three tests intests/test_cache.pycover the load path, the save path and the file mode; they fail on master and pass here, and the rest of the suite is green with and withoutatomicwritesinstalled.