Skip to content

Commit 68db011

Browse files
authored
Merge commit from fork
Fix a path traversal bug in LocalResourceUrlManager
2 parents af6b59d + 98f556f commit 68db011

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Framework/Framework/ResourceManagement/LocalResourceUrlManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,23 @@ protected virtual string GetVersionHash(ILocalResourceLocation location, IDotvvm
9393
return TryLoadAlternativeFile(name, hash, context);
9494
}
9595

96+
private static bool IsAllowedFileName(string name)
97+
{
98+
if (name.StartsWith("."))
99+
return false;
100+
if (name.Contains('/') || name.Contains('\\'))
101+
return false;
102+
if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
103+
return false;
104+
105+
return name.EndsWith(".map", StringComparison.OrdinalIgnoreCase);
106+
}
107+
96108
private ILocalResourceLocation? TryLoadAlternativeFile(string name, string hash, IDotvvmRequestContext context)
97109
{
110+
if (!IsAllowedFileName(name))
111+
return null;
112+
98113
if (alternateDirectories != null && alternateDirectories.TryGetValue(hash, out var filePath) && filePath != null)
99114
{
100115
var directory = Path.GetDirectoryName(Path.Combine(context.Configuration.ApplicationPhysicalPath, filePath));

0 commit comments

Comments
 (0)