1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Wrapped phishing detection feature behind feature flag (#5532)

This commit is contained in:
Conner Turnbull 2025-03-20 09:56:03 -04:00 committed by GitHub
parent 0eaab14628
commit 90b70ce354
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 3 deletions

View File

@ -1,14 +1,21 @@
using Bit.Core.Repositories; using Bit.Core;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Bit.Api.Controllers; namespace Bit.Api.Controllers;
[Route("phishing-domains")] [Route("phishing-domains")]
public class PhishingDomainsController(IPhishingDomainRepository phishingDomainRepository) : Controller public class PhishingDomainsController(IPhishingDomainRepository phishingDomainRepository, IFeatureService featureService) : Controller
{ {
[HttpGet] [HttpGet]
public async Task<ActionResult<ICollection<string>>> GetPhishingDomainsAsync() public async Task<ActionResult<ICollection<string>>> GetPhishingDomainsAsync()
{ {
if (!featureService.IsEnabled(FeatureFlagKeys.PhishingDetection))
{
return NotFound();
}
var domains = await phishingDomainRepository.GetActivePhishingDomainsAsync(); var domains = await phishingDomainRepository.GetActivePhishingDomainsAsync();
return Ok(domains); return Ok(domains);
} }
@ -16,6 +23,11 @@ public class PhishingDomainsController(IPhishingDomainRepository phishingDomainR
[HttpGet("checksum")] [HttpGet("checksum")]
public async Task<ActionResult<string>> GetChecksumAsync() public async Task<ActionResult<string>> GetChecksumAsync()
{ {
if (!featureService.IsEnabled(FeatureFlagKeys.PhishingDetection))
{
return NotFound();
}
var checksum = await phishingDomainRepository.GetCurrentChecksumAsync(); var checksum = await phishingDomainRepository.GetCurrentChecksumAsync();
return Ok(checksum); return Ok(checksum);
} }

View File

@ -2,6 +2,7 @@
using Bit.Core.Jobs; using Bit.Core.Jobs;
using Bit.Core.PhishingDomainFeatures.Interfaces; using Bit.Core.PhishingDomainFeatures.Interfaces;
using Bit.Core.Repositories; using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Settings; using Bit.Core.Settings;
using Quartz; using Quartz;
@ -12,21 +13,29 @@ public class UpdatePhishingDomainsJob : BaseJob
private readonly GlobalSettings _globalSettings; private readonly GlobalSettings _globalSettings;
private readonly IPhishingDomainRepository _phishingDomainRepository; private readonly IPhishingDomainRepository _phishingDomainRepository;
private readonly ICloudPhishingDomainQuery _cloudPhishingDomainQuery; private readonly ICloudPhishingDomainQuery _cloudPhishingDomainQuery;
private readonly IFeatureService _featureService;
public UpdatePhishingDomainsJob( public UpdatePhishingDomainsJob(
GlobalSettings globalSettings, GlobalSettings globalSettings,
IPhishingDomainRepository phishingDomainRepository, IPhishingDomainRepository phishingDomainRepository,
ICloudPhishingDomainQuery cloudPhishingDomainQuery, ICloudPhishingDomainQuery cloudPhishingDomainQuery,
IFeatureService featureService,
ILogger<UpdatePhishingDomainsJob> logger) ILogger<UpdatePhishingDomainsJob> logger)
: base(logger) : base(logger)
{ {
_globalSettings = globalSettings; _globalSettings = globalSettings;
_phishingDomainRepository = phishingDomainRepository; _phishingDomainRepository = phishingDomainRepository;
_cloudPhishingDomainQuery = cloudPhishingDomainQuery; _cloudPhishingDomainQuery = cloudPhishingDomainQuery;
_featureService = featureService;
} }
protected override async Task ExecuteJobAsync(IJobExecutionContext context) protected override async Task ExecuteJobAsync(IJobExecutionContext context)
{ {
if (!_featureService.IsEnabled(FeatureFlagKeys.PhishingDetection))
{
_logger.LogInformation(Constants.BypassFiltersEventId, "Skipping phishing domain update. Feature flag is disabled.");
return;
}
if (string.IsNullOrWhiteSpace(_globalSettings.PhishingDomain?.UpdateUrl)) if (string.IsNullOrWhiteSpace(_globalSettings.PhishingDomain?.UpdateUrl))
{ {
_logger.LogInformation(Constants.BypassFiltersEventId, "Skipping phishing domain update. No URL configured."); _logger.LogInformation(Constants.BypassFiltersEventId, "Skipping phishing domain update. No URL configured.");

View File

@ -177,6 +177,7 @@ public static class FeatureFlagKeys
public const string PM12276Breadcrumbing = "pm-12276-breadcrumbing-for-business-features"; public const string PM12276Breadcrumbing = "pm-12276-breadcrumbing-for-business-features";
public const string PM18794_ProviderPaymentMethod = "pm-18794-provider-payment-method"; public const string PM18794_ProviderPaymentMethod = "pm-18794-provider-payment-method";
public const string PM3553_MobileSimpleLoginSelfHostAlias = "simple-login-self-host-alias"; public const string PM3553_MobileSimpleLoginSelfHostAlias = "simple-login-self-host-alias";
public const string PhishingDetection = "phishing-detection";
public static List<string> GetAllKeys() public static List<string> GetAllKeys()
{ {