From c61953ebcc018528f2673d41dbbbde653faa635e Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Sat, 19 Sep 2026 11:22:55 +0200 Subject: [PATCH] crypto: add strict mode to --force-fips Allow --force-fips to take an optional provider or strict mode. Keep provider as the current default and explicit compatibility mode. In strict mode, return failure from the OpenSSL 3.4+ FIPS indicator callback when it reports a non-approved operation. Install the callback for enforcement without implicitly enabling diagnostics; --enable-fips-indicator-events remains the independent observation opt-in. Keep the bare form mapped to provider for compatibility, allowing the default to change to strict in a future major release. Preserve the mode when forwarding flags to child test processes, and keep the parser's internal mode storage out of process.allowedNodeEnvironmentFlags. Document the callback scope limitations and cover provider compatibility, validation, synchronous crypto, WebCrypto, Workers, and opt-in event publication. PR-URL: https://github.com/nodejs/node/pull/65645 Backport-PR-URL: https://github.com/nodejs/node/pull/66128 Assisted-by: Codex Signed-off-by: Filip Skokan Reviewed-By: Antoine du Hamel --- doc/api/cli.md | 21 ++- doc/api/crypto.md | 6 +- doc/api/diagnostics_channel.md | 9 +- doc/api/errors.md | 2 +- doc/node.1 | 16 +- lib/internal/process/per_thread.js | 3 + src/crypto/crypto_util.cc | 19 ++- src/node.cc | 2 +- src/node_options.cc | 23 ++- src/node_options.h | 1 + .../test-crypto-fips-indicator-strict.js | 153 ++++++++++++++++++ test/parallel/test-crypto-fips.js | 42 ++++- 12 files changed, 282 insertions(+), 15 deletions(-) create mode 100644 test/parallel/test-crypto-fips-indicator-strict.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 1ad92ee9f54..acbd1ff8bd7 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1397,15 +1397,34 @@ added: v12.12.0 Disable loading native addons that are not [context-aware][]. -### `--force-fips` + + +### `--force-fips[=mode]` Enable [FIPS mode][] at startup and prevent it from being disabled from script code. The same OpenSSL requirements as [`--enable-fips`][] apply. +An optional mode can be specified using `--force-fips=mode`: + +* `provider`: Preserve the OpenSSL FIPS provider's configured handling of + non-approved operations. This is the current default when the mode is + omitted. +* `strict`: Reject non-approved operations reported through the OpenSSL FIPS + indicator callback. This mode requires OpenSSL 3.4 or later. + +The `strict` mode only covers operations reported through the callback for +OpenSSL's default library context. It does not cover native addons that use +another `OSSL_LIB_CTX` or another copy of `libcrypto`, nor operation-specific +indicators that do not invoke the callback. + ### `--force-node-api-uncaught-exceptions-policy`