-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
I spent a good amount of time trying to figure out why a Configuration Provider using the PhysicalFileProvider refused to read a dot-prefixed file (E.g. .env).
It turns out, dot-prefixed files are considered sensitive:
runtime/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/ExclusionFilters.cs
Lines 15 to 23 in 75b6c99
| /// <summary> | |
| /// Equivalent to <c>DotPrefixed | Hidden | System</c>. Exclude files and directories when the name begins with a period, or has either <see cref="FileAttributes.Hidden"/> or <see cref="FileAttributes.System"/> is set on <see cref="FileSystemInfo.Attributes"/>. | |
| /// </summary> | |
| Sensitive = DotPrefixed | Hidden | System, | |
| /// <summary> | |
| /// Exclude files and directories when the name begins with period. | |
| /// </summary> | |
| DotPrefixed = 0x0001, |
It was introduced as part of this PR in the previous repository: aspnet/FileSystem#280
After finding this, I had two questions:
- Why are dot-prefixed files considered sensitive?
- Why are sensitive files excluded from
PhysicalFileProviderby default.
For further context, I'm working on an app where I need to read the configuration from a file called .env. I kept getting FileNotFoundExceptions and had to dig into the source code to find out why.
I've attempted to address the confusing error in this PR: #54717