zen icon indicating copy to clipboard operation
zen copied to clipboard

Consider adding StatusNoContent and StatusNotModified guards to `filter.go`

Open coderabbitai[bot] opened this issue 2 months ago • 2 comments
trafficstars

Context

This issue is a follow-up from PR #434 and the discussion in https://github.com/ZenPrivacy/zen-desktop/pull/434#discussion_r2330373830.

Problem

The filtering system in internal/filter/filter.go currently processes all HTTP responses for content injection (scriptlets, cosmetic rules, CSS rules, JS rules) without checking for specific status codes that shouldn't have their bodies modified.

Since there are multiple injectors (scriptletsInjector, cosmeticRulesInjector, cssRulesInjector, jsRuleInjector), we want to guard at a single centralized point rather than adding guards to each individual injector.

Proposed Enhancement

Consider adding guards in the HandleResponse method in filter.go to skip all injections for:

  • 204 No Content: These responses explicitly have no body content
  • 304 Not Modified: These responses typically don't include a body and shouldn't be modified

Current State

  • Content-Type checking is already handled in the isDocumentNavigation function (text/html requirement)
  • All injections happen within the if isDocumentNavigation(req, res) block in HandleResponse (lines ~283-314)
  • The injector currently proceeds for any response with matching rules and proper content type
  • Status code validation would add an additional safety layer at the centralized filtering point

Implementation Location

The guard should be added in internal/filter/filter.go in the HandleResponse method, either:

  1. As an additional condition in the isDocumentNavigation function, or
  2. As a separate check before the injections begin

Considerations

This enhancement requires careful consideration of:

  1. Whether these status codes can realistically occur in the context where the injectors run
  2. The performance impact of additional checks
  3. Whether the existing filter logic already prevents these cases
  4. Edge cases where these status codes might legitimately need processing

References

  • Original discussion: https://github.com/ZenPrivacy/zen-desktop/pull/434#discussion_r2330373830
  • Requested by: @anfragment

coderabbitai[bot] avatar Sep 08 '25 15:09 coderabbitai[bot]