cefsharp / cefsharp/CefSharp

Core - Validate CachePath is direct child of RootCachePath

Aperta
#4,949 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C#
Stelle
10.3k
Fork
2.9k
Merge medio
5g 22h
PR unite (30g)
4

Descrizione

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:
```csharp
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 https://github.com/cefsharp/CefSharp/issues/4925#issuecomment-2394952497_

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

La issue nomina CachePath e RootCachePath, ma non indica alcun file o test; inizia individuando la gestione esistente dei percorsi della cache e verificando come vengono attualmente trattati i percorsi non validi. Il lavoro è completato quando un CachePath specificato viene accettato solo se è uguale a RootCachePath o è un elemento figlio diretto, con i valori non validi rifiutati chiaramente in tutte le versioni di .NET supportate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.