chore: encrypt tenant NWC URL at rest and stop secret exposure in tenant APIs #58

Merged
hodlbod merged 1 commits from userAdityaa/caravel:encrypt-tenant-key into master 2026-05-05 20:42:12 +00:00
Contributor

Summary

This PR fixes #57 by encrypting tenant NWC URLs in storage, decrypting only for internal backend use, and redacting tenant API responses so secrets are never returned to clients.

Problem

Tenant NWC URLs were stored in plaintext and exposed through tenant API payloads, creating a high-risk secret leakage path.

closes #57

### Summary This PR fixes #57 by encrypting tenant NWC URLs in storage, decrypting only for internal backend use, and redacting tenant API responses so secrets are never returned to clients. ### Problem Tenant NWC URLs were stored in plaintext and exposed through tenant API payloads, creating a high-risk secret leakage path. closes #57
hodlbod reviewed 2026-05-02 14:22:51 +00:00
@@ -0,0 +107,4 @@
.decode(value)
.or_else(|_| base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(value))
.map_err(|e| anyhow!("NWC_URL_CIPHER_KEY must be 32-byte hex or base64: {e}"))
}
Owner

What if we just used nip 44? It would keep things a little lighter, one fewer dependency.

What if we just used nip 44? It would keep things a little lighter, one fewer dependency.
@@ -40,0 +61,4 @@
}
Ok(())
}
Owner

We don't need the migration, no data exists yet.

We don't need the migration, no data exists yet.
hodlbod reviewed 2026-05-04 15:43:54 +00:00
hodlbod left a comment
Owner

This all feels very coupled, can't we just parse the key and encrypt using rust-nostr? The nwc_url_cipher file seems like it should be unnecessary

This all feels very coupled, can't we just parse the key and encrypt using rust-nostr? The nwc_url_cipher file seems like it should be unnecessary
Author
Contributor

This all feels very coupled, can't we just parse the key and encrypt using rust-nostr? The nwc_url_cipher file seems like it should be unnecessary

I’ll dig into this further and assess whether it can be simplified and updated accordingly.

> This all feels very coupled, can't we just parse the key and encrypt using rust-nostr? The nwc_url_cipher file seems like it should be unnecessary I’ll dig into this further and assess whether it can be simplified and updated accordingly.
hodlbod reviewed 2026-05-04 21:51:42 +00:00
hodlbod left a comment
Owner

This feels both over and under-engineered. The NWC url is just a string field, on write it should be encrypted and stored, when sent to the frontend it should be converted into nwc_is_set or whatever. When we need to use it, we can decrypt on demand.

Some concrete changes:

  • Rename NWC_URL_CIPHER_KEY to ENCRYPTION_SECRET or something more generic. Add a utility to simply decrypt/encrypt using this key any string value instead of adding the Tenant impl block.
  • TenantResponse shouldn't have nwc_url on it
This feels both over and under-engineered. The NWC url is just a string field, on write it should be encrypted and stored, when sent to the frontend it should be converted into nwc_is_set or whatever. When we need to use it, we can decrypt on demand. Some concrete changes: - Rename NWC_URL_CIPHER_KEY to ENCRYPTION_SECRET or something more generic. Add a utility to simply decrypt/encrypt using this key any string value instead of adding the Tenant impl block. - TenantResponse shouldn't have nwc_url on it
@@ -39,0 +77,4 @@
return Err(anyhow!(
"unsupported legacy encrypted nwc_url envelope; re-save tenant configuration"
));
}
Owner

Why would this ever be true?

Why would this ever be true?
Author
Contributor

Why would this ever be true?

Sorry, that was an oversight on my side. Removed the unnecessary guard.

> Why would this ever be true? Sorry, that was an oversight on my side. Removed the unnecessary guard.
userAdityaa marked the pull request as work in progress 2026-05-05 12:51:48 +00:00
userAdityaa added 1 commit 2026-05-05 13:46:57 +00:00
userAdityaa force-pushed encrypt-tenant-key from af3f48168f to 95f9f0c0bf 2026-05-05 13:46:57 +00:00 Compare
Author
Contributor

Apologies for the code changes earlier, I’ll make sure to be more careful when submitting changes for review in future PRs.

Apologies for the code changes earlier, I’ll make sure to be more careful when submitting changes for review in future PRs.
userAdityaa marked the pull request as ready for review 2026-05-05 13:53:45 +00:00
Owner

Way better, thanks.

Way better, thanks.
hodlbod merged commit 80a86452d0 into master 2026-05-05 20:42:12 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: coracle/caravel#58