fix: [CODE-5062] Pre-Receive hook should not consider bypass flag for push rules#80
fix: [CODE-5062] Pre-Receive hook should not consider bypass flag for push rules#80abhinavcode wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe change removes dynamic bypass matching logic from the violation verification process in rule push handling, replacing it with hard-coded false values that mark all violations as non-bypassable, effectively disabling the bypass feature entirely. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
🧹 Nitpick comments (2)
app/services/protection/rule_push.go (2)
89-90: Redundant explicit zero-value assignments.
var violations types.RuleViolationsalready initialisesBypassableandBypassedtofalse(Go zero value). Lines 89–90 are no-ops that serve only as intent documentation. If the goal is self-documentation, a brief comment (// bypass intentionally disabled for pre-receive) would communicate this more clearly than redundant assignments; alternatively, they can be removed entirely.♻️ Suggested change
- violations.Bypassable = false - violations.Bypassed = false + // Bypass is intentionally disabled for the pre-receive hook push rules (CODE-5062).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/services/protection/rule_push.go` around lines 89 - 90, The explicit assignments setting violations.Bypassable = false and violations.Bypassed = false are redundant because var violations types.RuleViolations already zero-initializes those fields; remove those two assignments from rule_push.go (or replace them with a single clarifying comment such as "// bypass intentionally disabled for pre-receive" next to the violations declaration) so the code avoids no-op statements while preserving intent around the violations variable.
28-31: Misleading bypass configuration: configurable but silently ignored.
Bypass DefBypass(with itsjson:"bypass"tag) remains fully part of thePushrule's serialized schema.Sanitize()still validates it, andUserIDs()/UserGroupIDs()still return its contents. Now that bypass is hardcoded to disabled, any bypass list a user configures for a push rule will be accepted, validated, stored — and silently never applied.Consider one of:
- Removing
BypassfromPushentirely (breaking change to the schema, requires a migration).- Returning empty slices from
UserIDs()/UserGroupIDs()so the framework does not pre-load unnecessary bypass data.- At minimum, adding a comment on the field documenting that bypass is disabled for pre-receive push rules.
♻️ Minimal non-breaking mitigation (return empty from UserIDs/UserGroupIDs)
func (p *Push) UserIDs() ([]int64, error) { - return p.Bypass.UserIDs, nil + // Bypass is disabled for pre-receive push rules (CODE-5062). + return nil, nil } func (p *Push) UserGroupIDs() ([]int64, error) { - return p.Bypass.UserGroupIDs, nil + // Bypass is disabled for pre-receive push rules (CODE-5062). + return nil, nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/services/protection/rule_push.go` around lines 28 - 31, The Push struct exposes a Bypass field that is serialized/validated but is ignored at runtime; to avoid silently accepting unused bypass data, update the Push.UserIDs() and Push.UserGroupIDs() methods to always return empty slices (and nil error) so the framework won't preload bypass info, and add a comment on the Push.Bypass field noting that bypass is disabled for pre-receive push rules; optionally, also adjust Push.Sanitize() to skip/clear validation of Bypass to avoid storing/returning invalid-but-ignored bypass data.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@app/services/protection/rule_push.go`:
- Around line 89-90: The explicit assignments setting violations.Bypassable =
false and violations.Bypassed = false are redundant because var violations
types.RuleViolations already zero-initializes those fields; remove those two
assignments from rule_push.go (or replace them with a single clarifying comment
such as "// bypass intentionally disabled for pre-receive" next to the
violations declaration) so the code avoids no-op statements while preserving
intent around the violations variable.
- Around line 28-31: The Push struct exposes a Bypass field that is
serialized/validated but is ignored at runtime; to avoid silently accepting
unused bypass data, update the Push.UserIDs() and Push.UserGroupIDs() methods to
always return empty slices (and nil error) so the framework won't preload bypass
info, and add a comment on the Push.Bypass field noting that bypass is disabled
for pre-receive push rules; optionally, also adjust Push.Sanitize() to
skip/clear validation of Bypass to avoid storing/returning invalid-but-ignored
bypass data.
Summary by CodeRabbit