Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested queries support #5

Merged
merged 12 commits into from
Nov 30, 2021
Merged

Nested queries support #5

merged 12 commits into from
Nov 30, 2021

Conversation

franky47
Copy link
Member

@franky47 franky47 commented Nov 28, 2021

Encryption and decryption should be targeted better.

This PR adds support for precise control over which fields should be encrypted on write operations, and which fields should be attempted to be decrypted (ie: not all string leaves).

Why ?

  • Some nested queries may introduce leaf nodes with identical names, some encrypted, some not.
  • The path matching behaviour of v1.0.x was flaky and wouldn't match the intricacies of Prisma's nested writes
  • On the decryption side, some fields that appear to be encrypted could very well be encrypted using keys outside of the app's control (eg: E2EE apps like Chiffre.io).

Issues Encountered

Nested creates can potentially end up with cyclic graphs (A -> B -> C -> A). How does the query engine resolve those ?

Note: there seems to be an undocumented use of $use (pun intended), by setting 'engine' as the first argument and passing the callback as a second, the middlware will be plugged on the query engine, which has more info about the query structure. But it's an internal thing that could break and the datamodel there is just as hard to parse.

They are generated per-Model & per-operation, to make sure
we only encrypt the right things in case some nested fields
have the same name but aren't encrypted.

Note: targeted decryption has been disabled for now (WIP),
it will try to eagerly decrypt anything it sees.
@franky47 franky47 added the feature New feature or request label Nov 28, 2021
@coveralls
Copy link

coveralls commented Nov 28, 2021

Pull Request Test Coverage Report for Build 1523194943

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 81 of 92 (88.04%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+27.9%) to 86.413%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/index.ts 7 8 87.5%
src/visitor.ts 18 22 81.82%
src/encryption.ts 16 22 72.73%
Totals Coverage Status
Change from base Build 1511547196: 27.9%
Covered Lines: 98
Relevant Lines: 109

💛 - Coveralls

- Use @prisma/sdk to generate test DMMFs from schema strings
Use a depth-first search algorithm with branch-local
state to define which model we're working on, and follow
the model's connections down to the target fields.

This allows going through models that have no encrypted
fields, and handles any level of nesting both on the input
and the output objects.

Using a layered visitor pattern (object -> models -> cipher)
allows a single iteration for performance.
@franky47 franky47 marked this pull request as ready for review November 30, 2021 22:04
Logging can be done in the integration tests
with the `PRISMA_FIELD_ENCRYPTION_LOG`
environment variable (see .env).

See #4.
With multiple outgoing connections to the same target model,
and an un-encrypted model.
@franky47 franky47 merged commit 4820219 into next Nov 30, 2021
@github-actions
Copy link

🎉 This PR is included in version 1.1.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

github-actions bot commented Dec 1, 2021

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants