mirror of
https://github.com/bitwarden/server.git
synced 2025-01-23 22:01:28 +01:00
[SM-82] Add HttpController Attribute to protect secrets manager controllers during development (#2117)
* Adding development only attribute for sm API * dotnet format changes * Swapping attribute name to SecretsManager
This commit is contained in:
parent
be146a8f62
commit
8c0996efec
22
src/Api/Utilities/SecretsManagerAttribute.cs
Normal file
22
src/Api/Utilities/SecretsManagerAttribute.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace Bit.Api.Utilities
|
||||
{
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
|
||||
public class SecretsManagerAttribute : Attribute, IResourceFilter
|
||||
{
|
||||
public void OnResourceExecuting(ResourceExecutingContext context)
|
||||
{
|
||||
var env = context.HttpContext.RequestServices.GetService<IHostEnvironment>();
|
||||
if (!env.IsDevelopment())
|
||||
{
|
||||
context.Result = new NotFoundResult();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnResourceExecuted(ResourceExecutedContext context) { }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user