Repository navigation
Conversation
🔒 Scanned for secrets using gitleaks 8.28.0
…essing 🔒 Scanned for secrets using gitleaks 8.28.0
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6888 +/- ##
==========================================
+ Coverage 79.65% 79.71% +0.05%
==========================================
Files 565 565
Lines 63308 63376 +68
==========================================
+ Hits 50429 50518 +89
+ Misses 9896 9880 -16
+ Partials 2983 2978 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🔒 Scanned for secrets using gitleaks 8.28.0
… RemoveIdentityPureGo 🔒 Scanned for secrets using gitleaks 8.28.0
1 task
mihir20
added a commit
that referenced
this pull request
Apr 24, 2026
…6896) # Description `GZIPLocalFileHandler.RemoveIdentity` uses `exec("bash -c sed ...")` to strip suppressed user records from an NDJSON gzip file. Two problems with that: 1. **Shell injection surface**: every suppressed user ID is interpolated into a bash command. We sanitise with `regexp.QuoteMeta`, but those quotes *regex* metacharacters — it does not escape *shell* metacharacters. Inputs like `$(...)` or backticks remain risky. 2. **Does not scale with suppression list size**: sed runs every pattern against every line, so cost grows O(records × users). For 10k records × 100 users, it takes ~1.27s (1 MB/s). As part of this change, we are using a feature flag and adding native Go support for removing identity. we will be iterating line by line and deleting the lines that have the suppressed userIDs. [Benchmarks](#6888) ## Linear Ticket pipe-2904 ## Security - [ ] The code changed/added as part of this pull request won't create any security issues with how the software is being used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
GZIPLocalFileHandler.RemoveIdentityusesexec("bash -c sed ...")to strip suppressed user records from an NDJSON gzip file. Two problems with that:regexp.QuoteMeta, but that quotes regex metacharacters — it does not escape shellmetacharacters. Inputs like
$(...)or backticks remain risky.This PR adds two shell-free alternatives and benchmarks all three so we can pick a replacement with data:
RemoveIdentityRE— single compiled regex that extracts the id from the known key, then O(1) map lookup against a suppression set.RemoveIdentityPureGo— line-by-line lookup. Top-level-only key inspection (no nested false-positives).Both are O(records) regardless of suppression list size.
Benchmarks
All benchmarks on Apple M2 Pro, ~10% hit rate. Peak heap sampled via
runtime.MemStats.HeapAllocevery 50 µs.Standard scenarios (~137 B payloads)
Time / Throughput
RemoveIdentity(sed)RemoveIdentityRE(regex)RemoveIdentityPureGo(jsonparser)Peak live heap (MB)
Peak heap scales linearly with input size, not with user count — all three approaches hold ≈ input + output buffer in memory regardless of suppression list size. sed is slightly leaner on the largest
case because its output piping means the input buffer can be reclaimed earlier.
Large-file scenarios (~1 KB payloads)
Sed is excluded — at 2 GB × 10 users it would take ~250 s (extrapolated) and ~5.6 GB peak heap.
Time / Throughput
RemoveIdentityRERemoveIdentityPureGoPeak live heap (MB)
Note: large-file peak heap includes the benchmark test data slice (~1× input) that stays alive during measurement. In production (where
Read()loads the file directly intoh.records), peak memory is~1× input since in-place compaction eliminates the output buffer.
Key points:
RemoveIdentityREis the fastest across the board, ~2.2× faster thanPureGoat every data size. No JSON parse overhead.PureGois stricter only inspects the top-level id field, so nested"user_id"occurrences don't cause false drops.RemoveIdentityREpreserves the original sed textual-match semantics.Recommendation
Replace
RemoveIdentitywithRemoveIdentityRE— same match semantics as the current sed impl, removes the shell-injection surface, ~300× faster in the worst-case scenario (10k × 100 users).Keep
RemoveIdentityPureGoas a strictly-correct option for any call-site that needs to ignore nested occurrences.Correctness
gzip_correctness_test.godrives all three implementations through the same table of 11 cases (casings, regex/shell metacharacter ids, whitespace variants, partial-match guards, multi-idsuppression). Plus three documented behavioural quirks:
RemoveIdentityerrors on an empty users list (it builds an invalidsed -r -ecommand with no pattern).RemoveIdentityPureGoignores nested"user_id"occurrences; the sed/regex impls drop the line if any occurrence matches.Linear Ticket
< Replace with Linear Link ( create or search linear ticket) or >
Security