zen
zen copied to clipboard
Consider adding StatusNoContent and StatusNotModified guards to `filter.go`
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
isDocumentNavigationfunction (text/html requirement) - All injections happen within the
if isDocumentNavigation(req, res)block inHandleResponse(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:
- As an additional condition in the
isDocumentNavigationfunction, or - As a separate check before the injections begin
Considerations
This enhancement requires careful consideration of:
- Whether these status codes can realistically occur in the context where the injectors run
- The performance impact of additional checks
- Whether the existing filter logic already prevents these cases
- 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