Skip to content

feat: Add secret length validation#639

Closed
thesimplekid wants to merge 10 commits into
cashubtc:mainfrom
thesimplekid:max_secret_size
Closed

feat: Add secret length validation#639
thesimplekid wants to merge 10 commits into
cashubtc:mainfrom
thesimplekid:max_secret_size

Conversation

@thesimplekid
Copy link
Copy Markdown
Collaborator

@thesimplekid thesimplekid commented Mar 8, 2025

feat: Add secret length validation with 512-byte limit

feat: Add MAX_SECRET_LENGTH constant for secret length validation

Description


cashubtc/nuts#234

Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

feat: Add secret length validation with 512-byte limit

feat: Add MAX_SECRET_LENGTH constant for secret length validation
@thesimplekid thesimplekid changed the title feat: Add secret length validation in verify_proof method feat: Add secret length validation Mar 8, 2025
Comment thread crates/cashu/src/nuts/nut00/mod.rs Outdated
Comment thread crates/cashu/src/secret.rs Outdated
{
Self(secret.into())
let secret_str = secret.into();
if secret_str.chars().count() > crate::nuts::nut00::MAX_SECRET_LENGTH {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the same validation logic should apply as in the new custom Secret deserializer.

Maybe extract the logic in validate_secret (even though it's only length check now) and call it both in the deserializer and here? Extracting it in a method would make validation easier to manage or extend in the future.

Comment thread crates/cdk-common/src/error.rs Outdated
pub async fn verify_proof(&self, proof: &Proof) -> Result<(), Error> {
// Check that the secret length is not greater than MAX_SECRET_LENGTH characters
ensure_cdk!(
proof.secret.to_string().chars().count() <= cdk_common::nuts::nut00::MAX_SECRET_LENGTH,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would also be a good place to call the validate_secret mentioned above.

Comment thread crates/cashu/src/secret.rs
thesimplekid and others added 4 commits March 10, 2025 13:38
Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
@thesimplekid thesimplekid marked this pull request as draft March 20, 2025 11:43
@thesimplekid thesimplekid deleted the max_secret_size branch April 3, 2025 10:45
@thesimplekid thesimplekid restored the max_secret_size branch April 3, 2025 10:45
@thesimplekid
Copy link
Copy Markdown
Collaborator Author

Think i closed this by accident

@thesimplekid thesimplekid reopened this Apr 10, 2025
@thesimplekid thesimplekid deleted the max_secret_size branch June 5, 2025 11:51
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.

2 participants