Skip to content

feat(be): Remove compile time feature flags and simplify CSP#3705

Merged
aterga merged 12 commits intomainfrom
arshavir/remove-compile-time-feature-flags-from-ii-be
Mar 26, 2026
Merged

feat(be): Remove compile time feature flags and simplify CSP#3705
aterga merged 12 commits intomainfrom
arshavir/remove-compile-time-feature-flags-from-ii-be

Conversation

@aterga
Copy link
Copy Markdown
Collaborator

@aterga aterga commented Mar 24, 2026

Motivation

The compile-time feature flags (dummy_captcha and dev_csp) are now obsolete in the II backend. This PR removes them as a step towards reducing the build flavors to 1.

This also required simplifying the content security policy to reflect that there are no executable assets (e.g., HTML or JS) served by this canister anymore.

Changes

Feature flag removal

  • Remove dummy_captcha and dev_csp Cargo features from Cargo.toml
  • Remove feature-gated code: dummy captcha implementation, detailed CSP with integrity hashes
  • Remove --features dummy_captcha / --features dev_csp from scripts/build, Dockerfile, scripts/docker-build, and CI workflow
  • Clean up dfx.json build commands and scripts/test-canisters.sh
  • Keep II_DUMMY_CAPTCHA as a vite env var for the frontend build (still used by the frontend to register test dapp data)

CSP simplification

  • Simplify backend CSP to default-src 'none'; since the backend canister no longer serves executable assets
  • Remove integrity_hashes parameter from security_headers() and inline script extraction logic from assets.rs
  • Remove the content_security_policy_header() function entirely

Runtime captcha configuration

  • Make the v1 register endpoint respect the CaptchaDisabled / CaptchaTrigger::Dynamic config (previously it always validated captcha, relying on the compile-time dummy_captcha feature)
  • Share captcha_required() between v1 and v2 registration flows

Test updates

  • Change default test captcha config (arg_with_wasm_hash) to CaptchaDisabled since dummy_captcha is no longer available to make captcha solvable in tests
  • Add arg_with_captcha_enabled() helper for tests that specifically test captcha behavior
  • Fix captcha-specific tests to explicitly install with CaptchaEnabled
  • Fix dynamic captcha test to use high threshold during setup phase, then lower it to test captcha triggering
  • Update verify_security_headers to match the simplified CSP

@aterga aterga changed the title first feat(be): Remove compile time feature flags and simplify CSP Mar 24, 2026
Comment thread .github/workflows/canister-tests.yml Fixed
@aterga aterga force-pushed the arshavir/remove-compile-time-feature-flags-from-ii-be branch from 5294850 to f350c56 Compare March 24, 2026 16:40
@aterga aterga marked this pull request as ready for review March 24, 2026 16:40
Copilot AI review requested due to automatic review settings March 24, 2026 16:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes obsolete compile-time feature flags from the Internet Identity backend canister and simplifies HTTP security headers (notably CSP) to reflect that the backend no longer serves executable web assets.

Changes:

  • Simplified backend security_headers API and replaced the prior dynamic CSP generator with a fixed default-src 'none' policy.
  • Removed HTML inline-script integrity hash extraction and related test logic from backend asset initialization.
  • Removed the dummy_captcha / dev_csp feature declarations from the backend crate.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/internet_identity/src/http.rs Updates security_headers signature and simplifies CSP response header generation.
src/internet_identity/src/assets.rs Removes integrity-hash extraction and uses shared headers from security_headers when certifying assets.
src/internet_identity/src/anchor_management/registration/captcha.rs Removes feature-gated dummy captcha generation, leaving only the random captcha implementation.
src/internet_identity/Cargo.toml Removes the backend crate’s [features] section (including dummy_captcha and dev_csp).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internet_identity/src/anchor_management/registration/captcha.rs
Comment thread src/internet_identity/src/http.rs
aterga and others added 10 commits March 25, 2026 13:11
The feature flags were removed from Cargo.toml but the build scripts, Dockerfile, and CI workflow still referenced them, causing build failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…y_captcha

- Make v1 register endpoint respect CaptchaDisabled config (matching v2 behavior)
- Change default test captcha config to CaptchaDisabled since dummy_captcha feature is gone
- Fix captcha-specific tests to explicitly install with CaptchaEnabled
- Restore II_DUMMY_CAPTCHA env var for frontend vite builds (still needed as build-time env var)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
With the removal of the dummy_captcha feature, real captchas cannot be solved
in tests. Increase the dynamic captcha threshold so that registration rate
metric testing can complete without triggering unsolvable captchas.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…tion rates test

With current_rate window of 10s and reference_rate window of 100s, the
current/reference rate ratio is ~10x, requiring threshold_pct >= 900 to
avoid triggering captcha during the test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The backend CSP was simplified to 'default-src none;' by this PR, but
the test helper still expected the old detailed CSP.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This test tracks challenge removal from the inflight pool, which requires
captcha to be enabled so that check_challenge is called during registration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Install with CaptchaDisabled for the 25 base registrations, then upgrade
to Dynamic captcha config. This avoids triggering unsolvable captchas
during the setup phase.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ha test

Install with threshold_pct=1000 (high enough to prevent captcha during
setup), register 25 base identities to establish rate data, then upgrade
to threshold_pct=20 to verify captcha triggers at higher registration rates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aterga aterga requested a review from sea-snake March 26, 2026 16:58
@aterga aterga enabled auto-merge March 26, 2026 17:01
@aterga aterga added this pull request to the merge queue Mar 26, 2026
Merged via the queue into main with commit b448813 Mar 26, 2026
52 checks passed
@aterga aterga deleted the arshavir/remove-compile-time-feature-flags-from-ii-be branch March 26, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants