Skip to content

Adsblock to master#5

Merged
vkhangstack merged 7 commits into
masterfrom
adsblock
Dec 19, 2025
Merged

Adsblock to master#5
vkhangstack merged 7 commits into
masterfrom
adsblock

Conversation

@vkhangstack
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings December 19, 2025 07:29
@vkhangstack vkhangstack merged commit 7a227a2 into master Dec 19, 2025
4 of 5 checks passed
@vkhangstack vkhangstack deleted the adsblock branch December 19, 2025 07:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates comprehensive adblock functionality into the Custos application, enabling ad and tracker blocking through a Rust-based adblock engine with FFI bindings. The changes include filter list management, pagination for logs, and various UI/UX improvements.

Key changes:

  • Adds Rust adblock engine with C FFI bindings and Go CGO integration
  • Implements filter list management system with automatic downloading and caching
  • Adds cursor-based pagination for traffic logs with filtering capabilities

Reviewed changes

Copilot reviewed 37 out of 40 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
lib/adblock/src/lib.rs New Rust library implementing adblock engine with C FFI interface
lib/adblock/Cargo.toml Cargo configuration for the adblock static library
internal/adblock/engine.go Go CGO bindings for the Rust adblock engine
internal/adblock/stub.go Non-CGO stub implementation for builds without CGO
internal/proxy/server.go Integrates adblock engine into proxy server request handling
internal/core/types.go Adds adblock-related data structures (AdblockFilter, reason field)
internal/store/sqlite.go Implements database operations for adblock filters and paginated logs
app.go Adds filter management, seeding, and refresh logic
frontend/src/pages/AdblockFilters.tsx New UI page for managing adblock filter lists
frontend/src/pages/Traffic.tsx Adds pagination controls and reason column to traffic logs
nfpm.yaml Adds desktop integration files and post-removal script
scripts/postremove.sh Cleanup script for removing user data on uninstall
Comments suppressed due to low confidence (1)

scripts/postremove.sh:1

  • Using rm -rf without additional safety checks on user input is dangerous. Consider adding validation to ensure the path is within expected bounds and doesn't follow symlinks that could delete unintended directories.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

</span>
<td className="p-4 items-center flex justify-start">
{log.reason ? <span className={`px-2 py-0.5 rounded text-xs font-medium border ${log.reason === 'adsblock' ? 'bg-blue-500/10 text-blue-500 border-blue-500/20' : 'bg-purple-500/10 text-purple-500 border-purple-500/20'}`}>
{log.reason.toLocaleUpperCase()}
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'toLocaleUpperCase' to 'toLocaleUpperCase'. The method name should be 'toLocaleUpperCase()' (with 'Locale'), but more commonly 'toUpperCase()' is used for simple uppercase conversion.

Suggested change
{log.reason.toLocaleUpperCase()}
{log.reason.toUpperCase()}

Copilot uses AI. Check for mistakes.
Comment thread internal/proxy/server.go

if rule.Type == core.RuleBlock {
r.logBlock(req, domain, string(core.RuleSourceCustom), &core.Process{
r.store.IncrementAdblockHit(domain)
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adblock hit is incremented for custom rule blocks (line 256) when it should only be incremented for actual adblock engine matches. This causes incorrect statistics as custom rule blocks are counted as adblock hits.

Suggested change
r.store.IncrementAdblockHit(domain)

Copilot uses AI. Check for mistakes.
Comment thread internal/proxy/server.go
// ... continue to allow
// Check Blocklist
if r.blocklist.IsBlocked(domain) {
r.store.IncrementAdblockHit(domain)
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adblock hit is incremented for blocklist matches when this should be tracked separately or not at all, as blocklist hits are different from adblock filter hits.

Suggested change
r.store.IncrementAdblockHit(domain)

Copilot uses AI. Check for mistakes.
Comment thread internal/core/types.go
RuleSourceProtocolHttpsBlocked RuleType = "protection_https_blocked"
RuleSourceProtocolHttpAllowed RuleType = "protection_http_allowed"
RuleSourceProtocolHttpsAllowed RuleType = "protection_https_allowed"
RuleSourceAdsblock RuleType = "adsblock"
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'adsblock' to 'adblock' for consistency with other naming in the codebase.

Suggested change
RuleSourceAdsblock RuleType = "adsblock"
RuleSourceAdblock RuleType = "adblock"

Copilot uses AI. Check for mistakes.
Comment thread app.go
fmt.Printf("Failed to disable system proxy on shutdown: %v\n", err)
}
a.proxyServer.Stop()
ctx.Done()
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling ctx.Done() has no effect as it only returns a channel. If the intention is to cancel the context or wait for cancellation, this line should be removed or replaced with appropriate context cancellation logic.

Suggested change
ctx.Done()

Copilot uses AI. Check for mistakes.
Comment thread internal/proxy/conn.go
Comment on lines +98 to +99
// Force a final report in a goroutine to not block the connection close
go c.report()
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running the final report in a goroutine may cause the report to be lost if the program terminates before the goroutine completes. Consider using a sync.WaitGroup or ensuring the goroutine completes before shutdown.

Suggested change
// Force a final report in a goroutine to not block the connection close
go c.report()
// Force a final report before closing to ensure stats are persisted
c.report()

Copilot uses AI. Check for mistakes.
Comment thread app.go
Comment on lines +546 to +548
// Truncate before seeding as requested
a.store.ClearAdblockFilters()

Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing all adblock filters on every startup will delete user-added filters. This should only be done on first run or when explicitly requested by the user.

Suggested change
// Truncate before seeding as requested
a.store.ClearAdblockFilters()

Copilot uses AI. Check for mistakes.
Comment thread internal/proxy/server.go
Comment on lines +208 to +216
sEnabled := false
var engine *adblock.Engine

r.server.mu.RLock()
sEnabled = r.server.adblockEnabled
engine = r.server.adblockEngine
r.server.mu.RUnlock()

if sEnabled && engine != nil {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name 'sEnabled' is unclear. It should be renamed to 'adblockEnabled' to clearly indicate it stores the adblock enabled state.

Suggested change
sEnabled := false
var engine *adblock.Engine
r.server.mu.RLock()
sEnabled = r.server.adblockEnabled
engine = r.server.adblockEngine
r.server.mu.RUnlock()
if sEnabled && engine != nil {
adblockEnabled := false
var engine *adblock.Engine
r.server.mu.RLock()
adblockEnabled = r.server.adblockEnabled
engine = r.server.adblockEngine
r.server.mu.RUnlock()
if adblockEnabled && engine != nil {

Copilot uses AI. Check for mistakes.
setStats(currentStats);
setConnections(fetchedConns || []);

console.log("fetchedStats", fetchedStats);
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug console.log statement should be removed from production code.

Suggested change
console.log("fetchedStats", fetchedStats);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants