aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/slskd.example.yml4
-rw-r--r--src/slskd/Core/Options.cs17
-rw-r--r--src/slskd/Program.cs2
3 files changed, 17 insertions, 6 deletions
diff --git a/config/slskd.example.yml b/config/slskd.example.yml
index 40018508..6cbca906 100644
--- a/config/slskd.example.yml
+++ b/config/slskd.example.yml
@@ -159,6 +159,10 @@
# url_base: /
# content_path: wwwroot
# logging: false
+# cors:
+# allowed_origins:
+# - https://app.example.com
+# allow_credentials: false
# authentication:
# disabled: false
# username: slskd
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index b65fc383..69723b33 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -2093,7 +2093,7 @@ namespace slskd
public WebAuthenticationOptions Authentication { get; init; } = new WebAuthenticationOptions();
/// <summary>
- /// CORS options.
+ /// Gets CORS options.
/// </summary>
[Validate]
public CorsOptions Cors { get; init; } = new CorsOptions();
@@ -2392,18 +2392,25 @@ namespace slskd
}
}
+ /// <summary>
+ /// CORS options.
+ /// </summary>
public class CorsOptions : IValidatableObject
{
+ /// <summary>
+ /// Gets the list of CORS allowed origins.
+ /// </summary>
[Argument(default, "cors-allowed-origins")]
[EnvironmentVariable("CORS_ALLOWED_ORIGINS")]
- [Description("CORS allowed origins, comma separated")]
- [RequiresRestart]
+ [Description("list of allowed CORS origins")]
public string[] AllowedOrigins { get; init; } = null;
+ /// <summary>
+ /// Gets a value indicating whether CORS requests may include credentials.
+ /// </summary>
[Argument(default, "cors-allow-credentials")]
[EnvironmentVariable("CORS_ALLOW_CREDENTIALS")]
- [Description("CORS allow credentials (cookies, basic auth)")]
- [RequiresRestart]
+ [Description("allow CORS credentials for allowed origins")]
public bool AllowCredentials { get; init; } = false;
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index c2838dbe..8b22a7af 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -1098,7 +1098,7 @@ namespace slskd
await context.Response.WriteAsJsonAsync(context.Features.Get<IExceptionHandlerPathFeature>().Error.Message);
}));
- app.UseCors("AllowAll");
+ app.UseCors("AllowConfiguredOrigins");
if (OptionsAtStartup.Web.Https.Force)
{