Skip to content

Commit c5117b2

Browse files
cmmattsonCopilot
andauthored
Fix/handle missing src dst in traffic entries (#127)
* fix: guard against undefined src/dst in traffic entries Some exitTraffic entries from the Tailscale API omit the src field, causing a TypeError (Cannot read properties of undefined reading 'startsWith') in isIPAddress() which crashes the entire data loading pipeline. Changes: - Add null guard to isIPAddress() to return false for falsy input - Skip traffic entries with missing src or dst in processNetworkLogs() - Add null guards to extractIP() and extractPort() in ip-utils.ts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: guard against null IP values * fix: add comment about fix to guard against null values --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 28b06b3 commit c5117b2

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

frontend/src/lib/utils/ip-utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Extract IP from address (remove port if present)
22
export function extractIP(address: string): string {
3+
//Guard Against Null Values
4+
if (!address) return '';
35
// Handle IPv6 addresses like [fd7a:115c:a1e0::9001:b818]:62574
46
if (address.startsWith('[') && address.includes(']:')) {
57
return address.substring(1, address.indexOf(']:'));
@@ -20,6 +22,8 @@ export function extractIP(address: string): string {
2022

2123
// Extract port from address:port string
2224
export function extractPort(address: string): number | null {
25+
//Guard Against Null Values
26+
if (!address) return null;
2327
// Handle IPv6 addresses like [fd7a:115c:a1e0::9001:b818]:62574
2428
if (address.startsWith('[') && address.includes(']:')) {
2529
const portStr = address.split(']:')[1];
@@ -45,6 +49,9 @@ export function extractPort(address: string): number | null {
4549

4650
// Categorize IP addresses by type
4751
export function categorizeIP(ip: string): string[] {
52+
//Guard Against Null Values
53+
if (!ip) return ['null'];
54+
4855
// DERP servers
4956
if (ip === '127.3.3.40') return ['derp'];
5057

frontend/src/lib/utils/network-processor.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ interface ProcessedNetwork {
2020

2121
// Check if a string looks like an IP address (vs a device ID)
2222
function isIPAddress(value: string): boolean {
23+
//Guard against null values
24+
if (!value) return false;
2325
// IPv4: contains dots and numbers
2426
if (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(:\d+)?$/.test(value)) return true;
2527
// IPv6: contains colons but starts with [ or has many colons
@@ -144,6 +146,10 @@ export function processNetworkLogs(
144146
];
145147

146148
allTraffic.forEach((traffic) => {
149+
// Skip entries with missing src or dst (e.g. some exitTraffic entries
150+
// from the Tailscale API omit the src field)
151+
if (!traffic.src || !traffic.dst) return;
152+
147153
// Handle both IP:port format (live) and device ID format (historical)
148154
const srcIP = resolveToIP(traffic.src, devices);
149155
const dstIP = resolveToIP(traffic.dst, devices);

0 commit comments

Comments
 (0)