Skip to content

fix(rpc-password-generator): update password validation to match KDF password policy#58

Merged
CharlVS merged 5 commits intodevfrom
bugfix/rpc-password-generator
May 21, 2025
Merged

fix(rpc-password-generator): update password validation to match KDF password policy#58
CharlVS merged 5 commits intodevfrom
bugfix/rpc-password-generator

Conversation

@takenagain
Copy link
Copy Markdown
Contributor

@takenagain takenagain commented May 21, 2025

The password generator could intermittently generate passwords with 3 repeated characters, which would be rejected by KDF according to the password policy.

Summary by CodeRabbit

  • New Features

    • Introduced robust password validation with detailed error feedback for requirements such as length, digit, letter case, special characters, forbidden substrings, and repeated characters.
    • Enhanced password generation to ensure all security requirements are met before returning a password.
  • Bug Fixes

    • Passwords are now guaranteed to include all required character types and avoid forbidden patterns.
  • Tests

    • Added comprehensive tests covering password validation and generation, including Unicode and edge cases.

@takenagain takenagain self-assigned this May 21, 2025
@takenagain takenagain added the bug Something isn't working label May 21, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 21, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce a comprehensive password validation and generation system. Password generation now ensures compliance with strict security requirements, including checks for length, character diversity, and repetition. The password validation logic is encapsulated in a new method, and an extensive suite of unit tests is added to verify both validation and generation functionalities.

Changes

File(s) Change Summary
.../kdf_startup_config.dart Removed the generatePassword and _validateRPCPassword static methods from KdfStartupConfig. Updated password generation to use SecurityUtils.generatePasswordSecure(32) directly, removing the previous custom validation loop.
.../security_utils.dart Added the PasswordValidationError enum. Implemented robust password validation in checkPasswordRequirements. Enhanced generatePasswordSecure to guarantee passwords meet all requirements. Improved internal password generation logic for character diversity.
.../security_utils_test.dart Added a comprehensive test suite covering password validation and generation, including edge cases, Unicode support, and randomness checks.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant SecurityUtils

    Caller->>SecurityUtils: generatePasswordSecure(length)
    loop Until valid password
        SecurityUtils->>SecurityUtils: _generateSecurePassword(length)
        SecurityUtils->>SecurityUtils: checkPasswordRequirements(password)
        alt If password invalid
            SecurityUtils-->>SecurityUtils: Retry generation
        end
    end
    SecurityUtils-->>Caller: Return valid password
Loading

Poem

In the warren of code, we burrowed deep,
To guard our secrets, no password sheep.
With tests and checks for every case,
No "password" sneaks, nor three in place.
Secure and strong, our carrots stored—
The safest vault a bunny’s adored!
🥕🔐


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@takenagain
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (6)
packages/komodo_defi_types/lib/src/utils/security_utils.dart (3)

37-46: Doc-comment header has double /// prefix

Nit: the first two slashes are duplicated (/// ///).
This confuses some IDE doc-formatters and lints such as dartdoc’s “redundant prefix” rule.
Simply remove the extra pair.


26-33: Potentially unbounded retry loop in generatePasswordSecure

result is initialised to an empty string, then a while loop keeps calling _generateSecurePassword until the validator passes.
If a future change introduces a systematic bug in _generateSecurePassword (e.g. always producing three consecutive characters), this becomes an infinite loop that hangs the UI / isolate.

Consider:

-    while (!SecurityUtils.checkPasswordRequirements(result).isValid) {
+    // Fail‐safe: try a reasonable number of times, then throw.
+    const maxAttempts = 100;
+    var attempts = 0;
+    do {
+      if (++attempts > maxAttempts) {
+        throw StateError('Unable to generate a valid password '
+            'after $maxAttempts attempts');
+      }
       result = _generateSecurePassword(
         length,
         extendedSpecialCharacters: extendedSpecialCharacters,
       );
-    }
+    } while (!checkPasswordRequirements(result).isValid);

117-119: Random.secure() is recreated on every call

Instantiating Random.secure() is relatively expensive; generating multiple passwords in tight loops (e.g. unit tests) repeatedly hits the system CSPRNG.

Make a shared generator:

-    final random = Random.secure();
+    // Re-use a single secure RNG instance for the whole process.
+    final Random random = _rng;

and add at top-level:

static final Random _rng = Random.secure();
packages/komodo_defi_framework/lib/src/config/kdf_startup_config.dart (2)

9-10: komodo_defi_types.dart import might be redundant

After the refactor the file already imports
komodo_defi_type_utils.dart, which (usually) re-exports JsonMap,
JsonList, etc.
If the symbols from komodo_defi_types.dart are not referenced elsewhere
in this file, the additional import will trigger the
unused_import lint in analysis_options.yaml.

Please verify and remove or annotate with
// ignore: unused_import if it is indeed superfluous.


94-96: Hard-coded RPC password length duplicated

Both generateWithDefaults and noAuthStartup use the magic number 32.
Extract it into a const int _defaultRpcPasswordLength = 32;
to avoid divergence if the policy changes.

Also consider passing extendedSpecialCharacters: true to increase entropy once the off-by-one bug is fixed.

packages/komodo_defi_types/test/utils/security_utils_test.dart (1)

1-5: Tests rely on transitive export of SecurityUtils

komodo_defi_type_utils.dart may not export SecurityUtils /
PasswordValidationError. If that export is ever removed, the tests will
break silently at compile time.

Be explicit:

-import 'package:komodo_defi_types/komodo_defi_type_utils.dart';
+import 'package:komodo_defi_types/komodo_defi_type_utils.dart';
+import 'package:komodo_defi_types/src/utils/security_utils.dart';

(or the public barrel export if one exists).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d7dcb80 and 9d799b0.

📒 Files selected for processing (3)
  • packages/komodo_defi_framework/lib/src/config/kdf_startup_config.dart (3 hunks)
  • packages/komodo_defi_types/lib/src/utils/security_utils.dart (1 hunks)
  • packages/komodo_defi_types/test/utils/security_utils_test.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: setup

Comment thread packages/komodo_defi_types/lib/src/utils/security_utils.dart
Comment thread packages/komodo_defi_types/lib/src/utils/security_utils.dart
Comment thread packages/komodo_defi_types/test/utils/security_utils_test.dart
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented May 21, 2025

Visit the preview URL for this PR (updated for commit b793ea1):

https://komodo-defi-sdk--pr58-bugfix-rpc-password-wnwwwfrd.web.app

(expires Wed, 28 May 2025 15:41:35 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 7f9f5ac39928f333b6e8fcefb7138575e24ed347

@takenagain takenagain marked this pull request as ready for review May 21, 2025 15:40
@takenagain takenagain requested a review from CharlVS May 21, 2025 15:41
@CharlVS CharlVS requested a review from Copilot May 21, 2025 16:26
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 updates password validation and password generation to ensure that generated passwords comply with the KDF policy by enforcing required character criteria and avoiding security pitfalls such as consecutive repeated characters. Key changes include:

  • Introducing the PasswordValidationError enum with detailed error cases.
  • Implementing Unicode-aware password validation and refactoring generatePasswordSecure.
  • Standardizing the RPC password generation in KdfStartupConfig to use the new secure password generator.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/komodo_defi_types/lib/src/utils/security_utils.dart Added password validation logic and updated password generation to ensure robust security checks.
packages/komodo_defi_framework/lib/src/config/kdf_startup_config.dart Replaced the custom generatePassword method with the new secure password generator from SecurityUtils.

@CharlVS CharlVS merged commit 1291dfc into dev May 21, 2025
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants