Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HSTS to F# ApiServer and BwdServer #3665

Merged
merged 14 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fsharp-backend/src/ApiServer/ApiServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ let configureApp (packages : Packages) (appBuilder : WebApplication) =
|> fun app ->
LibService.Rollbar.AspNet.addRollbarToApp app rollbarCtxToMetadata None
|> fun app -> app.UseHttpsRedirection()
|> fun app -> app.UseHsts()
|> fun app -> app.UseRouting()
// must go after UseRouting
|> LibService.Kubernetes.configureApp LibService.Config.apiServerKubernetesPort
Expand All @@ -180,6 +181,7 @@ let configureServices (services : IServiceCollection) : unit =
LibService.Telemetry.TraceDBQueries
|> LibService.Kubernetes.configureServices [ LibBackend.Init.legacyServerCheck ]
|> fun s -> s.AddServerTiming()
|> fun s -> s.AddHsts(LibService.HSTS.setConfig)
|> ignore<IServiceCollection>

let run (packages : Packages) : unit =
Expand Down
4 changes: 4 additions & 0 deletions fsharp-backend/src/BwdServer/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ let configureApp (healthCheckPort : int) (app : IApplicationBuilder) =
(task {
let executionID = LibService.Telemetry.executionID ()
ctx.Items[ "executionID" ] <- executionID
setHeader
ctx
"Strict-Transport-Security"
"max-age=31536000; includeSubDomains; preload"
setHeader ctx "x-darklang-execution-id" (string executionID)
setHeader ctx "Server" "darklang"

Expand Down
9 changes: 9 additions & 0 deletions fsharp-backend/src/LibService/HSTS.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module LibService.HSTS

open System
open Microsoft.AspNetCore.HttpsPolicy

let setConfig (options : HstsOptions) =
options.Preload <- true
options.IncludeSubDomains <- true
options.MaxAge <- TimeSpan.FromDays 365
1 change: 1 addition & 0 deletions fsharp-backend/src/LibService/LibService.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Compile Include="Kubernetes.fs" />
<Compile Include="HeapAnalytics.fs" />
<Compile Include="Kestrel.fs" />
<Compile Include="HSTS.fs" />
<Compile Include="Init.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading