-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
73 lines (63 loc) · 2.68 KB
/
Copy pathProgram.cs
File metadata and controls
73 lines (63 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using SafeWebCore.Extensions;
using SharpCoreDB;
using SharpCoreDB.WebViewer.Models;
using SharpCoreDB.WebViewer.Services;
var builder = WebApplication.CreateBuilder(args);
var webViewerOptions = builder.Configuration.GetSection(WebViewerOptions.SectionName).Get<WebViewerOptions>() ?? new WebViewerOptions();
builder.WebHost.UseUrls($"https://{webViewerOptions.BindAddress}:{webViewerOptions.HttpsPort}");
builder.Services.Configure<WebViewerOptions>(builder.Configuration.GetSection(WebViewerOptions.SectionName));
builder.Services.AddHttpContextAccessor();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.Cookie.Name = ".SharpCoreDB.WebViewer.Session";
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Cookie.SameSite = SameSiteMode.Lax;
options.IdleTimeout = TimeSpan.FromMinutes(20);
});
const string CspSelf = "'self'";
builder.Services.AddNetSecureHeadersStrictAPlus(options =>
{
options.Csp = options.Csp with
{
StyleSrc = CspSelf,
StyleSrcElem = CspSelf,
ImgSrc = $"{CspSelf} data:",
FontSrc = CspSelf,
ConnectSrc = CspSelf,
// Trusted Types blocks innerHTML/document.write DOM manipulation used by our vanilla JS.
// Disable both directives; we enforce XSS safety through strict CSP nonce + strict-dynamic instead.
RequireTrustedTypesFor = string.Empty,
TrustedTypes = string.Empty
};
});
builder.Services.AddSharpCoreDB();
builder.Services.AddSingleton<IRecentConnectionsStore, RecentConnectionsStore>();
builder.Services.AddSingleton<IQueryWorkspaceStore, QueryWorkspaceStore>();
builder.Services.AddSingleton<ISampleDatabaseCatalog, SampleDatabaseCatalog>();
builder.Services.AddScoped<IViewerConnectionService, ViewerConnectionService>();
builder.Services.AddScoped<IViewerTransactionService, ViewerTransactionService>();
builder.Services.AddScoped<IMetadataService, MetadataService>();
builder.Services.AddScoped<IViewerQueryService, ViewerQueryService>();
builder.Services.AddRazorPages();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseNetSecureHeaders();
app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.MapRazorPages();
// IMPORTANT: create the default "scdb" database on first launch.
using (var scope = app.Services.CreateScope())
{
var sampleCatalog = scope.ServiceProvider.GetRequiredService<ISampleDatabaseCatalog>();
await sampleCatalog.EnsureDefaultDatabaseAsync().ConfigureAwait(false);
}
await app.RunAsync().ConfigureAwait(false);