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

Core - Validate CachePath is direct child of RootCachePath #4949

Open
amaitland opened this issue Oct 7, 2024 · 0 comments
Open

Core - Validate CachePath is direct child of RootCachePath #4949

amaitland opened this issue Oct 7, 2024 · 0 comments

Comments

@amaitland
Copy link
Member

          Yes this can be more subtle that one expects as well.  Specifying an invalid cachepath causes it to default back if you are running multiple instances this is going to run into the singleton problem which if you have the handler for you might catch quickly but if not the crash may not be apparent.  

I think the easiest decently bulletproof way to do this is something along the lines of:

if (! String.IsNullOrWhitespace(CachePath)){
 var di = DirectoryInfo(CachePath);
if (Path.GetRelativePath(di.FullPath,RootCachePath) != "." && Path.GetRelativePath(di.Parent.FullPath,RootCachePath) != ".")
 throw new ArgumentException("If specifying CachePath it must be equal to the RootCachePath or a direct child directory of it");
}

(That is code from my poor memory so almost certainly won't compile but the gyst:)

Granted GetRelativePath is .net std 2.1 so doesn't help most .net framework users. Pretty sure there is GetFinalPath or getfinaltarget or something as well but i think that is an even newer .net version.

One could pinvoke with GetFinalPathNameByHandle but that might be overkill. Could just force users to not use tricky naming so CachePath.Parent must directly equal rootcachepath or throw an error (as cef probably is using basic logic to determine if it should allow the cachepath without full resolution like the above).

Originally posted by @mitchcapper in #4925 (comment)

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

No branches or pull requests

1 participant