ArcArcGo: DuckDuckGo Proxy with Custom Branding

Cloudflare Worker that acts as a transparent proxy for DuckDuckGo with custom branding, URL rewriting, and JavaScript injection capabilities.

Cloudflare Workers JavaScript DuckDuckGo License
Stars Repo Size Forks Website

GitHub: 0xarchit/ArcArcGo
Live Demo: https://arcarcgo.0xarchit.is-a.dev

Screenshot

ArcArcGo Interface
ArcArcGo Interface

Overview

ArcArcGo demonstrates advanced Cloudflare Workers capabilities by intercepting requests, fetching content from DuckDuckGo, and modifying responses before serving them to clients with custom branding and functionality.


Architecture

Request Flow

  1. Client Request → Cloudflare Worker
  2. Worker Processing → DuckDuckGo Server
  3. Response Modification → Client
graph LR
    A[Client] --> B[Cloudflare Worker]
    B --> C[DuckDuckGo]
    C --> B
    B --> A
    B -.-> D[URL Rewriting + Branding]

Core Components

1. Event Listener

The worker uses a fetch event listener to intercept all incoming HTTP requests and delegates processing to the main handleRequest function.

2. Request Handler (handleRequest)

URL Construction

The worker extracts the pathname, search parameters, and hash from incoming requests and constructs the target DuckDuckGo URL while maintaining the original query structure.

Header Processing

Header Modifications:

  • Removed: Host, X-Forwarded-For (prevents detection as proxy)
  • Set: Standard browser Accept header
  • Set: Default User-Agent if not present

Response Processing

Response Header Modifications:

  • Removed: Content-Security-Policy (allows script injection)
  • Added: CORS header for cross-origin access

3. Content Type Handling

Non-HTML Content

Images, CSS, JavaScript, and other assets are passed through unchanged, maintaining original response body and headers.

HTML Content Processing

Uses TransformStream for real-time content modification without buffering the entire response.


URL Rewriting System

Pattern Matching

The worker uses comprehensive regex patterns to identify and rewrite URLs, including:

  • Standard HTML attributes: href, src, action in both double and single quotes
  • CSS URLs: url() declarations
  • Meta refresh: URL redirects in meta tags
  • JavaScript redirects: window.location, location.href, etc.
  • Data attributes: Custom data URLs for navigation
  • Absolute paths: Standalone paths in quotes
  • Event handlers: onclick, onchange, onsubmit attributes

URL Transformation Logic

1. Absolute URLs

Only processes DuckDuckGo URLs by stripping the domain and prepending the proxy base URL.

2. Relative URLs

Resolves relative URLs against the DuckDuckGo origin while maintaining query parameters.

3. Special Cases

  • Fragments (#): Preserved unchanged
  • Data URLs: Preserved unchanged
  • JavaScript URLs: Preserved unchanged
  • Event Handlers: Special processing for location changes

Branding System

Text Replacement

Real-time text replacement in HTML content using regex patterns to replace "DuckDuckGo" with "ArcArcGo" and handle possessive forms.

Logo Replacement

Regex-based logo replacement that identifies DuckDuckGo logo images and replaces them with the custom ArcArcGo logo.

JavaScript Injection

Dynamic branding through injected script that:

  • Text Replacement: Uses TreeWalker to traverse all text nodes
  • Title Replacement: Updates document title
  • Logo Replacement: Targets specific CSS selectors for logo images
  • Dynamic Monitoring: Uses MutationObserver for continuously added content
  • Multiple Triggers: Responds to load, DOMContentLoaded events, and periodic intervals

Stream Processing

Chunked Processing

The worker processes content in chunks to optimize memory usage and provide real-time response modification. It uses a buffer system with:

Buffer Management:

  • Size Threshold: 8192 bytes
  • Content Threshold: Presence of </body> tag
  • Final Processing: Script injection before response completion

Error Handling

The worker implements comprehensive error handling for:

  • Network connectivity issues
  • Invalid URL construction
  • Stream processing errors
  • Regex processing failures

All errors return a 500 status response with a descriptive error message.


Performance Considerations

Optimization Strategies

  1. Selective Processing: Only HTML content is modified
  2. Chunked Streaming: Real-time processing without buffering entire response
  3. Efficient Regex: Compiled patterns for fast matching
  4. Header Optimization: Minimal header modifications

Resource Usage

  • Memory: Stream-based processing minimizes memory usage
  • CPU: Regex operations on text chunks
  • Network: Direct proxy with minimal latency

Security Considerations

Mitigations Implemented

  1. CSP Removal: Enables script injection
  2. Header Sanitization: Removes tracking headers
  3. URL Validation: Prevents open proxy attacks
  4. Content Filtering: Only processes specific content types

Potential Risks

  • Open Proxy: Limited to DuckDuckGo domain
  • Script Injection: Controlled injection for branding only
  • Privacy: No logging or data collection

Deployment Guide

Prerequisites

  • Cloudflare account
  • Workers subscription (free tier available)

Deployment Steps

  1. Create Worker: In Cloudflare dashboard
  2. Deploy Code: Copy worker.js content
  3. Configure Routes: Set custom domain or use workers.dev subdomain
  4. Test Functionality: Verify search and branding

Configuration Options

  • Custom Logo: Modify newLogoSrc variable
  • Branding Text: Adjust replacement patterns
  • Target Domain: Change targetHost for different proxy targets

Troubleshooting

Common Issues

1. Script Injection Not Working

  • Cause: CSP blocking or timing issues
  • Solution: Verify CSP removal, check MutationObserver

2. URLs Not Rewriting

  • Cause: Pattern mismatch or encoding issues
  • Solution: Test regex patterns, check URL encoding

3. Performance Issues

  • Cause: Large content or complex patterns
  • Solution: Optimize buffer size, simplify regex patterns

Debug Techniques

  1. Console Logging: Add logging to worker (remove in production)
  2. Network Inspection: Check headers and response codes
  3. Content Validation: Verify HTML modifications

Limitations

Technical Limitations

  • JavaScript-Heavy Sites: May require additional pattern matching
  • Dynamic Content: MutationObserver helps but may miss rapid changes
  • Complex URLs: Some edge cases may not be covered
  • Terms of Service: May violate target site's ToS
  • Copyright: Logo and content modifications
  • Educational Use: Intended for learning purposes only


Conclusion

ArcArcGo demonstrates advanced Cloudflare Workers capabilities including:

  • Real-time content transformation
  • Complex regex-based URL rewriting
  • Dynamic JavaScript injection
  • Stream processing optimization
  • Practical proxy server development
  • Performance optimization techniques
  • Maintaining functionality of underlying service
  • Educational exploration of web proxy concepts

The implementation showcases how modern edge computing can be used to create sophisticated web proxies while maintaining the performance and functionality of the underlying service.