In the plugin development for DeepSeek Harness (DSH), fetching resources (images, webpages, audio, etc.) from external sources is a common requirement. If these URLs originate from user input or model output, they constitute an attack surface for SSRF (Server-Side Request Forgery). Attackers may exploit this vulnerability to access internal network services (such as http://127.0.0.1:5099/api) or cloud vendor metadata interfaces (such as http://169.254.169.254/latest/meta-data/iam/security-credentials/).
dsh-netguard is a DSH plugin designed to act as an “outbound network guardrail.” Through a netguard service and an optional fetch_url tool, it uniformly manages the address validity, size, and timeout of all outbound requests, preventing internal network exposure caused by errors in validation logic.
Core Features¶
The plugin provides the following capabilities:
- SSRF Protection: Only allows access to public network addresses, blocking private, internal, and special-use addresses (such as
127.0.0.1,169.254.169.254, etc.). - DNS Resolution Check: Validates every address resolved by DNS to prevent domains from resolving to internal networks.
- Hop-by-Hop Redirect Inspection: Re-validates the address at every hop of an HTTP redirect to prevent
302location headers from pointing to the internal network. - Streaming Size Limit: Counts bytes while reading; immediately disconnects if
maxBytesis exceeded to prevent memory exhaustion attacks. - Timeout Control: The entire request chain shares a single timeout budget to prevent long stalls or redirects from slowing down overall performance.
- Port Blacklist: Blocks common internal service ports (e.g., 22, 23, 25, 6379, 27017).
- IPv4/IPv6 Address Classification: Supports various IPv4 obfuscations (e.g.,
0x7f.1); IPv6 is restricted to2000::/3. - Tool Support: Provides a
fetch_urltool (disabled by default) for models to call to fetch public content.
Installation and Configuration¶
Installation¶
Execute the following in the DSH project directory:
dsh plugin --profile web add github:JackZo400/dsh-netguard
Configuration¶
Add a netguard service instance in the plugin configuration file. The following is an example of common parameters:
- insert:
- id: netguard
name: dsh-netguard
config:
allowedProtocols: ['http:', 'https:'] # Only allow HTTP/HTTPS
maxBytes: 8388608 # Maximum 8 MiB download per request
onOverflow: error # Throw error on limit exceeded; set to 'truncate' to truncate
timeoutMs: 20000 # Timeout shared by the entire chain
allowRedirects: true # Allow redirects, re-validate every hop
maxRedirects: 3
blockedPorts: [22, 23, 25, 6379, 11211, 27017] # Common internal ports
allowUrlCredentials: false # Prohibit user:pass in URL
allowSingleLabel: false # Prohibit single-label hostnames (e.g., http://intranet)
userAgent: dsh-netguard/0.1.0
enableTool: false # Whether to enable the fetch_url tool
Typical Usage¶
For Other Plugins¶
Get public bytes (suitable for downloading images or audio):
const netguard = ctx.get('netguard')
const bytes = await netguard.fetchPublicBytes(imageUrl, {
maxBytes: 8 * 1024 * 1024,
timeoutMs: 20_000
})
Get full response info (including status code, final address, redirect count, etc.):
const r = await netguard.fetchPublic(url, {
maxBytes: 64 * 1024,
onOverflow: 'truncate'
})
// Return value includes fields like finalUrl, status, bytes, truncated, redirects
Only validate URL safety without downloading:
const u = await netguard.assertPublicUrl(url) // Throws NetguardError if unsafe
Hostname and address determination (can be used independently):
// Synchronous check, does not query DNS, only blocks obvious formats
netguard.isPublicHost('127.0.0.1') // false
// Asynchronous check, queries DNS
await netguard.checkHost('demo.example.com') // Returns { ok, addresses, offender? }
// IP classification
netguard.classifyIp('::ffff:10.0.0.1') // Returns { isIp:true, public:false, reason:'PRIVATE' }
For Models (Disabled by Default)¶
If you need to allow the model to call external interfaces to fetch content, you must enable the tool in the configuration:
config:
enableTool: true
Once enabled, the model can use the fetch_url tool:
Fetch what is written in https://example.com/demo.html
Pure Function Logic¶
If the DSH environment is not required, you can directly import the pure function logic provided by the plugin:
import { isPublicIp, classifyIp } from 'dsh-netguard/src/ip.js'
import { assertPublicUrl } from 'dsh-netguard/src/guard.js'
Notes¶
Although the plugin provides comprehensive address checking, it has limitations in the following scenarios:
- DNS Rebinding (TOCTOU) Attacks: The plugin may use different DNS results during the resolution phase and the connection phase (e.g., domains with TTL=0). Attackers may exploit this time gap to bypass detection.
- Proxy Timing: The plugin’s address validation occurs before proxy configuration, so it cannot perceive the actual address accessed via a proxy.
- Content Safety: The plugin only verifies “whether it can go” and “how big it is,” but does not verify the safety of the returned content itself (e.g., malicious instructions in HTML).
- Special Redirects: Does not support
<meta http-equiv="refresh">or JavaScript redirects; only handles HTTP redirects. - Protocol Support: Does not support uploads, POST requests, or streaming long connections.
- DNSSEC: Does not perform DNSSEC verification; relies on the system resolver.
- Public Reverse Proxy: If an attacker sets up a reverse proxy on a public server pointing to the internal network, it cannot be detected at the address level.
- Port Blacklist: The blacklist is an approximation, not a complete list (e.g.,
8081,9090may also host internal services). - IPv6 Limitations: Only allows
2000::/3; a very small number of legitimate special IPv6 representations may be mistakenly blocked. - No Rate Limiting: The plugin does not limit request frequency or concurrency; quota control must be added externally.
Conclusion¶
dsh-netguard provides a solid outbound security layer for DSH plugins through strict address classification, hop-by-hop redirect inspection, and streaming rate limiting. It addresses common SSRF vulnerabilities that traditional regex matching cannot cover, such as obfuscated IPs, DNS resolving to internal networks, and redirect hijacking. Developers should adjust the maxBytes, timeoutMs, and blockedPorts parameters based on actual business needs.
Plugin Directory: SkillHub Plugin Directory
GitHub Repository: JackZo400/dsh-netguard