Skip to content

Commit a48f991

Browse files
Filter requests accessing TMPMEDIA_DIR folder. (#905)
* Filter requests accessing TMPMEDIA_DIR folder. * Filter access to private dir.
1 parent e24f91b commit a48f991

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal class GXRouting : IGXRouting
4444

4545
static Regex SDSVC_PATTERN = new Regex("([^/]+/)*(sdsvc_[^/]+/[^/]+)(\\?.*)*");
4646

47-
const string PRIVATE_DIR = "private";
47+
internal const string PRIVATE_DIR = "private";
4848
public Dictionary<string, string> servicesPathUrl = new Dictionary<string, string>();
4949
public Dictionary<String, Dictionary<string, SingleMap>> servicesMap = new Dictionary<String, Dictionary<string, SingleMap>>();
5050
public Dictionary<String, Dictionary<Tuple<string, string>, String>> servicesMapData = new Dictionary<String, Dictionary<Tuple<string, string>, string>>();

dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,22 @@ public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHos
370370
if (File.Exists(rewriteFile))
371371
AddRewrite(app, rewriteFile, baseVirtualPath);
372372

373+
string tempMediaDir = string.Empty;
374+
if (Config.GetValueOf("TMPMEDIA_DIR", out string mediaPath) && !PathUtil.IsAbsoluteUrlOrAnyScheme(mediaPath))
375+
{
376+
tempMediaDir = mediaPath;
377+
}
373378
app.UseStaticFiles(new StaticFileOptions()
374379
{
375380
FileProvider = new PhysicalFileProvider(LocalPath),
376381
RequestPath = new PathString($"{baseVirtualPath}"),
377382
OnPrepareResponse = s =>
378383
{
379-
var path = s.Context.Request.Path;
380-
if (path.HasValue && path.Value.IndexOf($"/{APP_SETTINGS}", StringComparison.OrdinalIgnoreCase)>=0)
384+
PathString path = s.Context.Request.Path;
385+
bool appSettingsPath = path.HasValue && path.Value.IndexOf($"/{APP_SETTINGS}", StringComparison.OrdinalIgnoreCase) >= 0;
386+
bool tempMediaPath = path.StartsWithSegments($"{baseVirtualPath}/{tempMediaDir}", StringComparison.OrdinalIgnoreCase);
387+
bool privatePath = path.StartsWithSegments($"{baseVirtualPath}/{GXRouting.PRIVATE_DIR}", StringComparison.OrdinalIgnoreCase);
388+
if (appSettingsPath || tempMediaPath || privatePath)
381389
{
382390
s.Context.Response.StatusCode = 401;
383391
s.Context.Response.Body = Stream.Null;

0 commit comments

Comments
 (0)