To show you how I work, here is an example using the topic VPNs.

As a senior developer and writer, I believe the best way to demonstrate my approach is to take a familiar, yet often misunderstood, topic and dissect it from a developer’s perspective. We won’t just look at the surface; we’ll peel back the layers, inspect the machinery, and even write some code to see how it interacts with the web technologies we use daily.

Today, our subject is the Virtual Private Network (VPN). You’ve seen the ads, you might even use one, but what’s happening under the hood? And more importantly, how does it impact us as developers building for the modern web? Let’s dive in and break it down.

Deconstructing the VPN: Beyond the “On” Button

At its core, a VPN is a service that creates a secure, encrypted connection over a less secure network, such as the public internet. Think of it as building a private, armored tunnel for your data to travel through the chaotic public highway of the internet. This process provides two primary benefits: privacy and anonymity.

The Core Principle: Encrypted Tunneling

When you connect to a VPN, your device (the client) establishes a connection with a VPN server. All your internet traffic is then routed through this connection.

  1. Encryption: Before your data leaves your device, the VPN client encrypts it. This scrambles the data, making it unreadable to anyone who might intercept it—your Internet Service Provider (ISP), network administrators, or malicious actors on a public Wi-Fi network.
  2. Tunneling: The encrypted data is then placed inside an outer packet and sent to the VPN server. This process is called tunneling. The outer packet is addressed to the VPN server, so your ISP only sees you connecting to a single server, not the dozens of websites and services you’re actually accessing.
  3. IP Masking: Once your traffic reaches the VPN server, it’s decrypted and sent to its final destination on the internet. When the destination server (e.g., google.com) sends data back, it sends it to the VPN server’s IP address, not yours. The VPN server then encrypts that data and sends it back to you through the secure tunnel. To the outside world, you appear to have the IP address of the VPN server. This is IP masking.

Key Protocols: The Engine Under the Hood

Not all VPNs are created equal. The security, speed, and reliability of a VPN are heavily dependent on the tunneling protocol it uses. As of 2025, two protocols dominate the landscape:

  • OpenVPN: For years, this has been the industry standard. It’s open-source, highly configurable, and considered extremely secure. It uses the robust OpenSSL library and can run over either TCP (for reliability) or UDP (for speed), making it versatile. Its primary drawback is that its codebase is large, and it can sometimes be slower than more modern alternatives.
  • WireGuard: The modern challenger. WireGuard is a newer protocol with a significantly smaller codebase (around 4,000 lines compared to OpenVPN’s hundreds of thousands). This makes it easier to audit and debug. It’s built for speed and uses state-of-the-art cryptography. By default, it runs over UDP and is designed to be incredibly fast, making it ideal for streaming and gaming. Most major VPN providers now offer WireGuard as a primary option.

Older protocols like PPTP and L2TP/IPsec still exist but are now largely considered insecure or outdated and should be avoided.

The Developer’s Lens: How VPNs Interact with Web Technologies

This is where it gets interesting for us. How does this encrypted tunnel affect the websites and applications we build? Let’s explore with some practical code.

The IP Address: The Obvious Change

The most direct impact of a VPN is on the client’s perceived IP address. Any server-side language will see the IP of the VPN server, not the user’s real IP. This is fundamental for services that use IP-based geolocation.

Here’s a simple PHP snippet to demonstrate. If you run this on a web server and access it with and without a VPN, you’ll see a different IP address.

php
<?php
// Set the header to display plain text for clarity
header(‘Content-Type: text/plain’);

// Get the IP address of the connecting client
$client_ip = $_SERVER[‘REMOTE_ADDR’];

echo “Hello! Your IP address appears to be: ” . $client_ip . “\n\n”;

// A simple (and not foolproof) check to see if it’s an IPv4 or IPv6
if (filter_var($client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
echo “This looks like an IPv4 address.\n”;
} elseif (filter_var($client_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
echo “This looks like an IPv6 address.\n”;
}

// When you connect through a VPN, the IP address shown here
// will be that of the VPN server, not your home router.
?>

This is the intended behavior and is the basis for bypassing geo-restrictions. As a developer, if you’re building a service that needs to know a user’s country (e.g., for licensing content), you must be aware that the IP address is not a reliable source of truth.

Geolocation: Bypassing and Detecting

While a VPN effectively masks your IP-based location, modern browsers have another tool for finding you: the HTML5 Geolocation API. This is a crucial distinction.

The navigator.geolocation API does not use the user’s IP address. Instead, it asks the browser to determine the location using the most accurate method available on the device, which could be:

  • GPS (on a mobile device)
  • Information about nearby Wi-Fi networks
  • Cell tower triangulation

This means a user connected to a VPN server in Japan can still report their precise physical location in Berlin if they grant a website permission to use the Geolocation API.

Here’s how you can request it in JavaScript:

javascript
// Check if the Geolocation API is supported
if (‘geolocation’ in navigator) {
console.log(‘Geolocation API is available.’);

const options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};

navigator.geolocation.getCurrentPosition(success, error, options);

function success(position) {
const lat = position.coords.latitude;
const lon = position.coords.longitude;
console.log(Your precise location:);
console.log(Latitude: ${lat}, Longitude: ${lon});
console.log(This location was determined by your device, not your IP address.);
}

function error(err) {
console.warn(ERROR(${err.code}): ${err.message});
console.log(‘User likely denied the location request or location services are off.’);
}

} else {
console.log(‘Geolocation API is not available in this browser.’);
}

The developer takeaway: If you need a user’s actual physical location, the Geolocation API is far more reliable than their IP, but it requires explicit user consent.

The Leaky Faucets: DNS and WebRTC Leaks

Here’s where we get into the advanced, “gotcha” scenarios. A poorly configured VPN or browser can “leak” information outside the encrypted tunnel, potentially revealing your real IP address.

DNS Leaks: When you type example.com into your browser, your computer sends a DNS request to a DNS server to resolve that domain name into an IP address. Ideally, this request should go through the VPN tunnel to the VPN provider’s DNS servers. A DNS leak occurs when the request bypasses the tunnel and goes directly to your ISP’s DNS servers, revealing your browsing activity to your ISP.

WebRTC Leaks: This is a major concern for web developers. WebRTC (Web Real-Time Communication) is a technology built into modern browsers that allows for direct peer-to-peer communication (for video chat, file sharing, etc.) without needing an intermediary server. To establish this connection, browsers need to exchange IP address information, including your local and public IP addresses. A browser with WebRTC enabled can be tricked into revealing your real public IP address, even when you’re behind a VPN.

You can create a rudimentary WebRTC IP detection script. This snippet demonstrates the principle:

javascript
// This is a simplified example to demonstrate the concept.
// It may not work in all browsers or environments without tweaks.

// Create a peer connection. The ‘stun’ server is used to discover IP addresses.
// We use a public Google STUN server for this example.
const pc = new RTCPeerConnection({
iceServers: [{ urls: ‘stun:stun.l.google.com:19302’ }]
});

// Create a dummy data channel to trigger ICE candidate gathering.
pc.createDataChannel(”);

// When an ICE candidate (a potential connection address) is found, this event fires.
pc.onicecandidate = (event) => {
// If the event has a candidate and the candidate has an address…
if (event.candidate && event.candidate.address) {
// We are only interested in public IP addresses. Local IPs (e.g., 192.168.x.x) are filtered out.
if (!event.candidate.address.match(/^(192.168.|10.|172.(1[6-9]|2[0-9]|3[0-1]))/)) {
console.log(‘Potential Public IP found via WebRTC:’, event.candidate.address);
// This IP could be your REAL public IP, even when using a VPN.
}
}
};

// Start the process of gathering candidates.
pc.createOffer()
.then(offer => pc.setLocalDescription(offer))
.catch(err => console.error(err));

Most quality VPN providers now build in DNS and WebRTC leak protection, but as developers, it’s essential to understand that these browser-level APIs can behave in ways that subvert network-level privacy tools.

Conclusion

My approach to any technology is to move from the abstract to the concrete. We started with the high-level concept of a VPN—an encrypted tunnel. We then dove into the specifics: the protocols like OpenVPN and WireGuard that power it. Finally, we brought it into our world, the world of web development, with practical code examples.

We’ve seen that a VPN’s interaction with the web is a complex dance:

  • It reliably masks the server-side view of a user’s IP (PHP example).
  • It can be completely bypassed by device-level APIs like navigator.geolocation (JS example).
  • It can be undermined by low-level browser features like WebRTC, creating potential leaks (JS example).

Understanding these nuances is what separates a novice from an expert. It’s not enough to know what a tool does; you have to understand how it works and where its boundaries lie. This deep-dive, code-driven methodology is how I tackle any technical challenge, ensuring robust, aware, and effective solutions.


Frequently Asked Questions

Q1: Can a website always detect if I’m using a VPN?
A: Not always, but they can make educated guesses. Websites can check if an IP address belongs to a known datacenter (where most VPN servers are hosted) instead of a residential ISP. They can also look for signs like many users connecting from the same IP, or they can use techniques like the WebRTC leak detection shown in the article to find a mismatch between the VPN’s IP and the user’s real IP.

Q2: You mentioned OpenVPN and WireGuard. Is WireGuard always the better choice?
A: “Better” depends on the use case. For most users, WireGuard is superior due to its incredible speed, modern cryptography, and simplicity. However, OpenVPN has been battle-tested for nearly two decades and offers more configuration flexibility (like running over TCP, which can be useful on restrictive networks). For pure performance, WireGuard usually wins. For maximum compatibility and time-tested reliability, OpenVPN is still a solid choice.

Q3: If I use a VPN, does that mean I’m safe from the navigator.geolocation API revealing my location?
A: No, you are not safe from it. The navigator.geolocation API does not rely on your IP address. It uses on-device hardware and data like GPS, Wi-Fi hotspots, and cell towers to determine your physical location. A VPN does not interfere with these systems. The only protection is to deny the website’s request for location permission when your browser prompts you.

Similar Posts