Home / Function/ isRemotePath() — astro Function Reference

isRemotePath() — astro Function Reference

Architecture documentation for the isRemotePath() function in path.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  d7463885_f985_b234_5ab2_077e4be21032["isRemotePath()"]
  f5377c99_3ce3_1abd_148f_93394ff5efe2["path.ts"]
  d7463885_f985_b234_5ab2_077e4be21032 -->|defined in| f5377c99_3ce3_1abd_148f_93394ff5efe2
  4525e360_2c67_0c4f_35df_a9eadf0f5b45["isParentDirectory()"]
  4525e360_2c67_0c4f_35df_a9eadf0f5b45 -->|calls| d7463885_f985_b234_5ab2_077e4be21032
  style d7463885_f985_b234_5ab2_077e4be21032 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/internal-helpers/src/path.ts lines 103–184

export function isRemotePath(src: string) {
	if (!src) return false;

	// Trim leading/trailing whitespace
	const trimmed = src.trim();
	if (!trimmed) return false;

	// Recursively decode URL-encoded characters to catch multi-level obfuscation
	let decoded = trimmed;
	let previousDecoded = '';
	let maxIterations = 10; // Prevent infinite loops on malformed input

	while (decoded !== previousDecoded && maxIterations > 0) {
		previousDecoded = decoded;
		try {
			decoded = decodeURIComponent(decoded);
		} catch {
			// If decoding fails (e.g., invalid %), stop and use what we have
			break;
		}
		maxIterations--;
	}

	// Check for Windows paths first (C:\, D:\, C:file, etc.)
	// This needs to be before the backslash check
	if (/^[a-zA-Z]:/.test(decoded)) {
		// Windows path with drive letter - always local
		return false;
	}

	// Check for Unix absolute path (starts with / but not // or /\)
	// This needs to be before the backslash check
	if (decoded[0] === '/' && decoded[1] !== '/' && decoded[1] !== '\\') {
		return false;
	}

	// Any backslash at the start is probably trouble. Treat as remote.
	if (decoded[0] === '\\') {
		return true;
	}

	// Protocol-relative URLs are remote
	if (decoded.startsWith('//')) {
		return true;
	}

	// Try to parse as URL to check for protocols and credentials
	try {
		// Try with a mock base URL for relative URLs that might have protocols
		const url = new URL(decoded, 'http://n');
		// Check for credentials first - ANY URL with credentials is suspicious
		if (url.username || url.password) {
			return true;
		}

		if (decoded.includes('@') && !url.pathname.includes('@') && !url.search.includes('@')) {
			// If the original string had an @ but it wasn't in the pathname or search,
			// it must have been in the authority section (credentials or domain).
			// Since we already checked for credentials, this is something dodgy.
			return true;
		}
		// If the input had its own protocol, it would override the base
		if (url.origin !== 'http://n') {
			// It had its own protocol - check what it is
			const protocol = url.protocol.toLowerCase();

			// Only file: protocol without credentials is considered local
			if (protocol === 'file:') {
				return false;
			}
			// All other protocols are remote (http:, https:, ftp:, ws:, data:, etc.)
			return true;
		}
		// If we can parse it both with and without a base URL, it's probably remote
		if (URL.canParse(decoded)) {
			return true;
		}
		return false;
	} catch {
		return true;
	}

Domain

Subdomains

Frequently Asked Questions

What does isRemotePath() do?
isRemotePath() is a function in the astro codebase, defined in packages/internal-helpers/src/path.ts.
Where is isRemotePath() defined?
isRemotePath() is defined in packages/internal-helpers/src/path.ts at line 103.
What calls isRemotePath()?
isRemotePath() is called by 1 function(s): isParentDirectory.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free