Security rules
NGB040: Plaintext network transport
Reports network connections to non-local hosts over unencrypted protocols: http:// URLs in HttpClient, fetch(), XMLHttpRequest, navigator.sendBeacon() and EventSource, ws:// URLs in WebSocket / RxJS webSocket(), and http:// / ws:// API URLs in production environment files.
| Property | Value |
|---|---|
| Rule ID | NGB040 |
| Category | Sensitive data & payment security |
| Default severity | medium |
| CWE | CWE-319 |
| Built-in presets | recommended: error, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports network connections to non-local hosts over unencrypted protocols: http:// URLs in HttpClient, fetch(), XMLHttpRequest, navigator.sendBeacon() and EventSource, ws:// URLs in WebSocket / RxJS webSocket(), and http:// / ws:// API URLs in production environment files. Requests that carry credentials, an Authorization header or a sensitive body are high severity.
Why it matters
From an HTTPS page browsers block such requests as mixed content, so in a correctly served app they simply fail — when they work, it is because the app itself runs over HTTP, the code executes during SSR in Node.js, or inside a hybrid shell. In all of those cases tokens, cookies and personal data cross the network unencrypted and can be read or modified by anyone on the path.
Detection behavior and supported patterns
- Requests (see NGB026) whose URL has a constant
http://host/ws://hostprefix environment.ts/environment.prod.ts/environment.production.ts: string properties named*Url,*Uri,*Endpoint,*Host,api,socket, … withhttp:///ws://values- Local hosts are ignored:
localhost,127.x,0.0.0.0,[::1],*.localhost,*.local,host.docker.internal, private 10.x / 192.168.x addresses - High severity with
withCredentials,credentials: "include", anAuthorizationheader, a WebSocket (cookies are sent on the handshake) or a body classified as credential/payment data
Example
const socket = new WebSocket('ws://realtime.example.com/feed');this.http.post('http://api.example.com/login', { username, password });Safer alternative
const socket = new WebSocket('wss://realtime.example.com/feed');this.http.post('https://api.example.com/login', { username, password });Remediation
Use https:// and wss:// for every non-local endpoint, serve the application over HTTPS with HSTS, and keep plain-HTTP URLs only in development environment files.
False-positive considerations
- Internal hostnames that are only reachable on a trusted network (e.g.
http://intranet-api) are reported; they still travel unencrypted.
Known limitations
- URLs assembled from configuration that is not a constant (
environment.apiUrlwith a non-constant value, runtime config files) are only covered through the environment-file check. - The serving protocol of the application itself (HTTP vs HTTPS, HSTS) is not visible.
References
Run it
ngbastion explain NGB040