Skip to content

Conversation

@john-royal
Copy link
Collaborator

@john-royal john-royal commented Oct 2, 2025

Might close #1062. What do we think?

Uses AES-256-GCM with scrypt-generated keys.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 2, 2025

Open in StackBlitz

npm i https://pkg.pr.new/alchemy-run/alchemy@1063

commit: 71538ca

@john-royal john-royal changed the title fix(core): use scrypt for key derivation feat(core): use aes-256 and scrypt for secret encryption Oct 2, 2025
@github-actions
Copy link

github-actions bot commented Oct 2, 2025

🚀 Website Preview Deployed

Your website preview is ready!

Preview URL: https://d84f147c-alchemy-website.alchemy-run.workers.dev

This preview was built from commit 1508515


🤖 This comment will be updated automatically when you push new commits to this PR.

@john-royal john-royal changed the title feat(core): use aes-256 and scrypt for secret encryption feat(core): improve secret encryption Oct 2, 2025
Copy link
Collaborator

@Mkassabov Mkassabov left a comment

Choose a reason for hiding this comment

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

works tests passing

);
}
if (typeof value["@secret"] === "object") {
if (typeof value["@secret"] === "object" && "data" in value["@secret"]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if data is not present? Do we just skip it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Quick answer: no, we don't skip it. The data property indicates an encrypted object; otherwise it's an encrypted string. This is the same as before.

-      if (typeof value["@secret"] === "object") {
+      if (typeof value["@secret"] === "object" && "data" in value["@secret"]) {
        return new Secret(
          JSON.parse(
            await decryptWithKey(value["@secret"].data, scope.password),
          ),
        );
      }
      return new Secret(await decryptWithKey(value["@secret"], scope.password));

Why the change? The encrypted value is now an object with properties, so typeof value["@secret"] === "object" is always true. Checking for the data property is how we differentiate the two cases.

The serialization logic is completely unchanged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was looking for the code that is handling backwards compatibility (decrypting old secrets). Can you point that out to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@john-royal john-royal marked this pull request as ready for review October 6, 2025 20:17
@sam-goodwin sam-goodwin merged commit c8e5487 into main Oct 28, 2025
16 checks passed
@sam-goodwin sam-goodwin deleted the john/improve-encryption branch October 28, 2025 18:27
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.

Use pwhash to encrypt secrets

5 participants