mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
set cors policies to only allow web vault origin (#787)
* set cors policy to only allow web vault * vault cors policy service
This commit is contained in:
parent
2daca941f3
commit
cf70a5e480
@ -169,7 +169,7 @@ namespace Bit.Api
|
||||
app.UseRouting();
|
||||
|
||||
// Add Cors
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(h => true)
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(o => o == globalSettings.BaseServiceUri.Vault)
|
||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||
|
||||
// Add authentication and authorization to the request pipeline.
|
||||
|
@ -1,13 +0,0 @@
|
||||
using IdentityServer4.Services;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.IdentityServer
|
||||
{
|
||||
public class AllowAllCorsPolicyService : ICorsPolicyService
|
||||
{
|
||||
public Task<bool> IsOriginAllowedAsync(string origin)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
}
|
20
src/Core/IdentityServer/VaultCorsPolicyService.cs
Normal file
20
src/Core/IdentityServer/VaultCorsPolicyService.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using IdentityServer4.Services;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.IdentityServer
|
||||
{
|
||||
public class VaultCorsPolicyService : ICorsPolicyService
|
||||
{
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
|
||||
public VaultCorsPolicyService(GlobalSettings globalSettings)
|
||||
{
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public Task<bool> IsOriginAllowedAsync(string origin)
|
||||
{
|
||||
return Task.FromResult(origin == _globalSettings.BaseServiceUri.Vault);
|
||||
}
|
||||
}
|
||||
}
|
@ -382,7 +382,7 @@ namespace Bit.Core.Utilities
|
||||
}
|
||||
|
||||
services.AddTransient<ClientStore>();
|
||||
services.AddTransient<ICorsPolicyService, AllowAllCorsPolicyService>();
|
||||
services.AddTransient<ICorsPolicyService, VaultCorsPolicyService>();
|
||||
services.AddScoped<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
|
||||
services.AddScoped<IProfileService, ProfileService>();
|
||||
services.AddSingleton<IPersistedGrantStore, PersistedGrantStore>();
|
||||
|
@ -101,7 +101,7 @@ namespace Bit.Events
|
||||
app.UseRouting();
|
||||
|
||||
// Add Cors
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(h => true)
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(o => o == globalSettings.BaseServiceUri.Vault)
|
||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||
|
||||
// Add authentication and authorization to the request pipeline.
|
||||
|
@ -102,7 +102,7 @@ namespace Bit.Notifications
|
||||
app.UseRouting();
|
||||
|
||||
// Add Cors
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(h => true)
|
||||
app.UseCors(policy => policy.SetIsOriginAllowed(o => o == globalSettings.BaseServiceUri.Vault)
|
||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||
|
||||
// Add authentication to the request pipeline.
|
||||
|
Loading…
Reference in New Issue
Block a user