nager / Nager.PublicSuffix

.NET public suffix domain parser
MIT License
155 stars 22 forks source link

fix unauthorized exception #49

Closed panos-konstantellos closed 3 years ago

panos-konstantellos commented 3 years ago

Path.GetTempPath checks the existance of some environment variables and return the first path found. If none is found, then it returns the windows temp directory ( C:/Windows/Temp ). In sites hosted in IIS none of the environment variables is present so the windows temp directory is used. In windows temp directory all users can create files. By default, users can access or modify only the files they created.

So the problem is that the first IIS website will create the "publicsuffixcache.dat" file in C:/Windows/Temp/ directory with read/write permissions to the application pool assigned to this website. Any other IIS website running under a different application pool will get UnauthorizedException.

tinohager commented 3 years ago

Thank you for your pull request. I do not want to include IIS specific code here. I understand your problem here is my approach.

var poolId = Environment.GetEnvironmentVariable("APP_POOL_ID", EnvironmentVariableTarget.Process);
WebTldRuleProvider(cacheProvider: new FileCacheProvider($"publicsuffixcache-{poolId}.dat"))
panos-konstantellos commented 3 years ago

Thank you for your immediate response. I have already implemented my own ICacheProvider ( which saves to application uploads folder ) and I provide it to WebTldRuleProvider constructor, so that's fine for my case.

It's fine that you dont want to include IIS specific code. The only reason that made me send this pull request is because I considered the code tested and fully functional up until I deployed the second application.

What about forcing the package consumer provide a baseDirectory for FileCacheProvider?

tinohager commented 3 years ago

I like implementations where I don't have to make many settings to get started. But then have the freedom to configure it when I need it.