Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HTML.CEF/CefSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public bool Init(ReadOnlySpan<char> pBaseDir, IHtmlResourceHandler resourceHandl
string baseDir = new(pBaseDir);
string chromiumDir = AppContext.BaseDirectory;
string rootCachePath = Path.Combine(baseDir, "cache", "chromium");
if (OperatingSystem.IsWindows() && LowIntegrityLabel.GetLocalAppDataLow() is string localAppDataLow)
rootCachePath = Path.Combine(localAppDataLow, "Source.NET", "cache", "chromium");

if (OperatingSystem.IsWindows() && !LowIntegrityLabel.Apply(rootCachePath))
resourceHandler.Message($"Chromium: failed to set a low integrity label on {rootCachePath}, cookies and storage will not persist.\n");
Expand Down
15 changes: 15 additions & 0 deletions HTML.CEF/LowIntegrityLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ static partial class LowIntegrityLabel
const int SeFileObject = 1;
const uint LabelSecurityInformation = 0x00000010;

static readonly Guid LocalAppDataLowFolderId = new("A520A1A4-1780-4FF6-BD18-167343C5AF16");

[LibraryImport("shell32.dll")]
private static partial int SHGetKnownFolderPath(in Guid folderId, uint flags, nint token, out nint path);

[LibraryImport("advapi32.dll", EntryPoint = "ConvertStringSecurityDescriptorToSecurityDescriptorW", StringMarshalling = StringMarshalling.Utf16)]
private static partial int ConvertStringSecurityDescriptorToSecurityDescriptor(string stringSecurityDescriptor, uint revision, out nint securityDescriptor, nint securityDescriptorSize);

Expand All @@ -29,6 +34,16 @@ static partial class LowIntegrityLabel
[LibraryImport("kernel32.dll")]
private static partial nint LocalFree(nint mem);

public static string? GetLocalAppDataLow() {
int result = SHGetKnownFolderPath(LocalAppDataLowFolderId, 0, 0, out nint path);
try {
return result == 0 ? Marshal.PtrToStringUni(path) : null;
}
finally {
Marshal.FreeCoTaskMem(path);
}
}

static bool IsApplied(string directory) {
if (GetNamedSecurityInfo(directory, SeFileObject, LabelSecurityInformation, 0, 0, 0, out _, out nint securityDescriptor) != 0)
return false;
Expand Down
Loading