Skip to content

Consider adding StatusNoContent and StatusNotModified guards to filter.go #22

@coderabbitai

Description

@coderabbitai

Context

This issue is a follow-up from PR ZenPrivacy/zen-desktop#434 and the discussion in ZenPrivacy/zen-desktop#434 (comment).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions