mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
adjust cors origin checks (#800)
* allow cors from bitwarden.com on cloud * allow file:// cors for safari extension * fix missing paren
This commit is contained in:
parent
448157b07c
commit
6bc7a3cdc0
@ -169,7 +169,7 @@ namespace Bit.Api
|
|||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
// Add Cors
|
// Add Cors
|
||||||
app.UseCors(policy => policy.SetIsOriginAllowed(o => o == globalSettings.BaseServiceUri.Vault)
|
app.UseCors(policy => policy.SetIsOriginAllowed(o => CoreHelpers.IsCorsOriginAllowed(o, globalSettings))
|
||||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||||
|
|
||||||
// Add authentication and authorization to the request pipeline.
|
// Add authentication and authorization to the request pipeline.
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
using IdentityServer4.Services;
|
using Bit.Core.Utilities;
|
||||||
|
using IdentityServer4.Services;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Bit.Core.IdentityServer
|
namespace Bit.Core.IdentityServer
|
||||||
{
|
{
|
||||||
public class VaultCorsPolicyService : ICorsPolicyService
|
public class CustomCorsPolicyService : ICorsPolicyService
|
||||||
{
|
{
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public VaultCorsPolicyService(GlobalSettings globalSettings)
|
public CustomCorsPolicyService(GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> IsOriginAllowedAsync(string origin)
|
public Task<bool> IsOriginAllowedAsync(string origin)
|
||||||
{
|
{
|
||||||
return Task.FromResult(origin == _globalSettings.BaseServiceUri.Vault);
|
return Task.FromResult(CoreHelpers.IsCorsOriginAllowed(origin, _globalSettings));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -595,5 +595,16 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
return httpContext.Connection?.RemoteIpAddress?.ToString();
|
return httpContext.Connection?.RemoteIpAddress?.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsCorsOriginAllowed(string origin, GlobalSettings globalSettings)
|
||||||
|
{
|
||||||
|
return
|
||||||
|
// Web vault
|
||||||
|
origin == globalSettings.BaseServiceUri.Vault ||
|
||||||
|
// Safari extension origin
|
||||||
|
origin == "file://" ||
|
||||||
|
// Product website
|
||||||
|
(!globalSettings.SelfHosted && origin == "https://bitwarden.com");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
services.AddTransient<ClientStore>();
|
services.AddTransient<ClientStore>();
|
||||||
services.AddTransient<ICorsPolicyService, VaultCorsPolicyService>();
|
services.AddTransient<ICorsPolicyService, CustomCorsPolicyService>();
|
||||||
services.AddScoped<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
|
services.AddScoped<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
|
||||||
services.AddScoped<IProfileService, ProfileService>();
|
services.AddScoped<IProfileService, ProfileService>();
|
||||||
services.AddSingleton<IPersistedGrantStore, PersistedGrantStore>();
|
services.AddSingleton<IPersistedGrantStore, PersistedGrantStore>();
|
||||||
|
@ -101,7 +101,7 @@ namespace Bit.Events
|
|||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
// Add Cors
|
// Add Cors
|
||||||
app.UseCors(policy => policy.SetIsOriginAllowed(o => o == globalSettings.BaseServiceUri.Vault)
|
app.UseCors(policy => policy.SetIsOriginAllowed(o => CoreHelpers.IsCorsOriginAllowed(o, globalSettings))
|
||||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||||
|
|
||||||
// Add authentication and authorization to the request pipeline.
|
// Add authentication and authorization to the request pipeline.
|
||||||
|
@ -102,7 +102,7 @@ namespace Bit.Notifications
|
|||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
// Add Cors
|
// Add Cors
|
||||||
app.UseCors(policy => policy.SetIsOriginAllowed(o => o == globalSettings.BaseServiceUri.Vault)
|
app.UseCors(policy => policy.SetIsOriginAllowed(o => CoreHelpers.IsCorsOriginAllowed(o, globalSettings))
|
||||||
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());
|
||||||
|
|
||||||
// Add authentication to the request pipeline.
|
// Add authentication to the request pipeline.
|
||||||
|
Loading…
Reference in New Issue
Block a user