Skip to main content

Secure Use of Feature Flags and Toggles

🌟 Objective​

To establish good practices for the secure use of feature flags (or toggles), with a focus on:

  • Minimising the risk of failures in production;
  • Enabling progressive and reversible deliveries;
  • Reinforcing traceability, governance and formal validation;
  • Preventing abuse or uncontrolled behaviour at runtime.

🧬 What Feature Flags are​

Feature flags are mechanisms that make it possible to activate or deactivate functionality without a new deployment, based on configuration rules. They are widely used for:

  • Progressive delivery;
  • Canary releases;
  • A/B testing;
  • Failure containment;
  • Operational management of critical functionality.

Common types of toggles​

TypeDescriptionPractical example
Release ToggleControls functionality under developmentNew API visible only to the internal team
Ops ToggleSwitches technical flows or sensitive integrations on/offTemporarily deactivating the sending of emails
Permission ToggleDefines who can access a functionalityOnly admins access internal dashboards
Experiment ToggleSupports experiments and optimisations by user groupShowing a new layout to 50% of users
Kill SwitchDeactivates functionality immediatelyInterrupting notifications after an incident

🛠️ How to apply​

🔐 Security and isolation​

  • Never use toggles as a substitute for access control;
  • Evaluate toggles in the backend - not only in the frontend;
  • Avoid client-side toggles for sensitive logic;
  • Ensure that all the associated logical paths are testable.

🛡️ Traceability and metadata​

Each toggle must have:

  • A unique and descriptive name;
  • An owner (responsible team or person);
  • A scope (environment, group, tenant, region...);
  • An activation condition and an expiry condition;
  • A functional and security justification.

📜 Management as code​

  • Manage toggles as infrastructure (e.g. Feature Flags as Code);
  • Version the configuration (YAML, JSON, etc.);
  • Apply via PRs, with review and formal approval.

🧪 Example of toggle metadata​

toggle: enable_enhanced_logging
description: Ativa logging estendido para debugging
owner: equipa-devsecops
enabled_by_default: false
scope: ["staging", "grupo-beta"]
expires_after: 2025-12-01
justification: Necessário para investigação de comportamento anómalo

⚠️ Risks and bad practices​

Anti-patternConsequence
Toggle without an ownerNobody knows who controls it
No expiryAccumulated technical debt
Evaluation only in the frontendBypass possible through UI manipulation
Silent toggle (no logs)Difficulty in debugging and auditing
No defined fallbackUnpredictable behaviour if switched off

✅ Good practices​

  • Define a periodic review SLA (e.g. all toggles reviewed monthly);
  • Alert on toggles active for more than 60 days;
  • Block merges of code with toggles without metadata;
  • Validate the alternative paths (with and without the toggle active);
  • Include toggles in the release approval process.

🧰 Supporting tools​

ToolTypeNotes
LaunchDarklySaaSDashboards, multi-language SDKs
UnleashOpen Source / SaaSSelf-hosted, rollout strategy
FlagsmithSaaS / Open SourceIntegration with GitOps and RBAC
FeatureHubOpen SourceFocus on multiple teams, multi-tenancy

📎 Cross-references​

Document / ChapterRelation to this topic
Ch. 01 - Risk ManagementRisk assessment associated with toggles
Ch. 06 - Secure DevelopmentTestability of conditional paths
Ch. 10 - Security TestingA/B tests, induced failures and fallback
Ch. 11 - Secure DeploymentToggles as an execution control mechanism
Ch. 12 - Monitoring and OperationsActive observation of behaviour with toggles

🌟 Toggles are powerful - but only when used with discipline, control and traceability.
They must be treated as critical runtime assets, with direct implications for security and operational risk.