Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4310 +/- ##
==========================================
- Coverage 89.29% 89.21% -0.09%
==========================================
Files 425 425
Lines 19915 19940 +25
==========================================
+ Hits 17783 17789 +6
- Misses 2132 2151 +19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a150e2a to
42fb158
Compare
elias-ba
left a comment
There was a problem hiding this comment.
Hey @midigofrank this is really a good solution for a hard problem. I have few observations and questions. Could you check them and let me know what you think ?
|
|
||
| config :lightning, Lightning.Scrubber, | ||
| max_credential_sensitive_values: | ||
| env!("MAX_CREDENTIAL_SENSITIVE_VALUES", :integer, 50) |
There was a problem hiding this comment.
Should we add this to .env.example ? And also maybe to DEPLOYMENT.md ?
There was a problem hiding this comment.
I didn't think it was necessary given the default was already a higher a value. But yeah, let me include it in the DEPLOYMENT.md docs
There was a problem hiding this comment.
Agreeing with Frank here (disclaimer I rarely look at or use .env.example), while we usually throw in an exhaustive list of options in that file (essentially listing the defaults) it's such a niche option probably fine to not include it.
| {%{}, types} | ||
| |> Ecto.Changeset.cast(params, [:value]) | ||
| |> maybe_add_error(valid?, error, touched) | ||
| |> validate_sensitive_values_count(body, touched) |
There was a problem hiding this comment.
This parses the body string again via parse_for_validation/1, but it was already parsed in parse_body/1 above. Could we consider passing the already-parsed body_json to avoid double parsing ?
There was a problem hiding this comment.
No it doesn't. We need the body as a map and body_json is a binary. It uses the body and it only parses the body if it is a binary
There was a problem hiding this comment.
I'm with Elias here, it does get parse twice when it's a string. we enter via validate_body, calling parse_body with a binary and validate_sensitive_value_count which called parse_for_validation. Also the the parse_body taking a string and parsing it as a map and then in another match it takes a non-empty map and encodes it as a string - thats hurting my brain!
There was a problem hiding this comment.
Thinking some more, while I'm sure it does get parsed twice when it's a string; the previous (i.e. current) implementation in this component smells a bit now around the validation logic.
We don't use CredentialBody.changeset here, I'm not sure why though. That would require a bit of work to change.
| {:error, "contains too many sensitive keys (250). Max allowed is 200"} | ||
| """ | ||
| def validate_sensitive_values_count(body) do | ||
| max_values = Lightning.Config.max_credential_sensitive_values() |
There was a problem hiding this comment.
What happens to existing credentials that already exceed this limit? If a user tries to update an unrelated field on a credential with 100+ sensitive values, will the update fail? Could we consider whether a migration or audit is needed to identify any existing credentials over the limit ?
There was a problem hiding this comment.
Nothing happens to them if they don't touch the body. In the prod db, the highest has 19. It's only the irregular one that has 500 and it will be dealt with at a user level.
| String.downcase(k) in @safe_keys || is_nil(v) | ||
| end) | ||
| |> Enum.map(fn {_k, v} -> v end) | ||
| |> Enum.uniq() |
There was a problem hiding this comment.
Good optimization. Just noting this subtly changes the return value. Previously duplicate values were included multiple times. Should be fine but worth a sanity check that no code path relied on the duplicate count.
There was a problem hiding this comment.
Yeah, we're good. The scrubber looks for the values as it scrubs. Duplicate values would just mean that the scrubber would make extra iterations
Description
This PR does 2 things:
MAX_CREDENTIAL_SENSITIVE_VALUES. By default, it's50Closes #4307
Validation steps
MAX_CREDENTIAL_SENSITIVE_VALUES=2 mix phx.serverPlease disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy
Pre-submission checklist
:owner,:admin,:editor,:viewer)