fix: sort attackProtection arrays on export to prevent spurious diffs (#1440) - #1460
Open
harshithRai wants to merge 2 commits into
Open
fix: sort attackProtection arrays on export to prevent spurious diffs (#1440)#1460harshithRai wants to merge 2 commits into
harshithRai wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1460 +/- ##
==========================================
+ Coverage 80.43% 80.46% +0.03%
==========================================
Files 163 163
Lines 7712 7724 +12
Branches 1708 1711 +3
==========================================
+ Hits 6203 6215 +12
Misses 810 810
Partials 699 699 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
harshithRai
marked this pull request as ready for review
August 14, 2026 05:46
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.
🔧 Changes
Fixes non-deterministic ordering of enum-like arrays under
attackProtectionon export. Previously each export re-serialized these arrays in whatever order the Auth0 API returned, producing spurious git diffs even when nothing changed.sortAttackProtectionArrays()insrc/context/defaults.ts- recursively sorts primitive arrays within the attackProtection subtree (e.g.shields,admin_notification_frequency,allowlist). Arrays of objects are left untouched.src/context/yaml/handlers/attackProtection.ts(YAML export)src/context/directory/handlers/attackProtection.ts(directory export)Shape
The array values are reordered on export; keys and structure are unchanged. Applies to YAML (
tenant.yaml→attackProtection.*) and directory (attack-protection/*.json).YAML (
tenant.yaml):Directory (
attack-protection/brute-force-protection.json):before:
{ "shields": ["user_notification", "block"] }after:
{ "shields": ["block", "user_notification"] }The first export after this change shows a one-time diff as arrays settle into sorted order; subsequent exports are stable. No effect on deploy/import - the API treats these arrays as order-insensitive.
📚 References
🔬 Testing
Unit tests - added a
sortAttackProtectionArrayssuite intest/context/defaults.test.js(sorts primitive arrays across the subtree; output is identical regardless of input order; object arrays left untouched). Existingtest/context/yaml/attackProtection.test.jsandtest/context/directory/attackProtection.test.jspass unchanged.Manual - exported a real tenant twice into separate folders and diffed, for both formats:
export -f yaml: two consecutive exports are byte-identical (diffclean); previously the arrays reordered between runs.export -f directory:attack-protection/brute-force-protection.jsonshieldsoutput as["block", "user_notification"](sorted).Dry-run: verified sorting on export does not alter dry-run behavior: the dry-run comparator (
src/tools/calculateDryRunChanges.ts) already normalizes array order before comparing primitive arrays, so it treats these arrays as order-insensitive. Sorting the exported file cannot introduce or suppress a detected change.📝 Checklist