jackwener/OpenCLI · error · ArgumentError

${label} must point to linkedin.com

Error message

${label} must point to linkedin.com

What it means

assertSafeLinkedinUrl validates that a caller-supplied LinkedIn URL is safe to use. After requiring an https URL with no embedded credentials or port, it checks the hostname and throws ArgumentError when the host is not linkedin.com or www.linkedin.com. This prevents misuse by ensuring only LinkedIn's canonical domains are accepted.

Source

Thrown at clis/linkedin/shared.js:100

  return /linkedin\.com\/(?:login|checkpoint|authwall|uas)/i.test(text)
    || /\b(sign in|log in|join linkedin|captcha|verification required)\b/i.test(text)
    || /(请登录|登录领英|安全验证)/.test(text);
}

export function assertSafeLinkedinUrl(value, label, fallbackPath = '/') {
  const raw = normalizeWhitespace(value || `https://www.linkedin.com${fallbackPath}`);
  let parsed;
  try {
    parsed = new URL(raw, 'https://www.linkedin.com');
  } catch {
    throw new ArgumentError(`${label} must be a LinkedIn URL`);
  }
  const host = parsed.hostname.toLowerCase();
  if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) {
    throw new ArgumentError(`${label} must be an https LinkedIn URL without credentials or port`);
  }
  if (host !== 'linkedin.com' && host !== 'www.linkedin.com') {
    throw new ArgumentError(`${label} must point to linkedin.com`);
  }
  return parsed.toString();
}

export function requireStringArg(args, key, label = key) {
  const value = normalizeWhitespace(args?.[key]);
  if (!value) throw new ArgumentError(`${label} is required`);
  return value;
}

export function parseLimit(value, fallback, max) {
  if (value === undefined || value === null || value === '') return fallback;
  const parsed = Number(value);
  if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {
    throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);
  }
  return parsed;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the canonical https://www.linkedin.com/... form of the URL (expand any short links first).
  2. Remove any username:password credentials, non-https scheme, or explicit port from the URL.
  3. If you have a locale subdomain (e.g. fr.linkedin.com), switch to www.linkedin.com.
  4. Verify the URL with `new URL(...)` and check hostname equals 'linkedin.com' or 'www.linkedin.com' before calling.

Example fix

// before
await url({ url: 'https://lnkd.in/eXaMpLe' });
// after
await url({ url: 'https://www.linkedin.com/in/some-profile/' });
Defensive patterns

Strategy: validation

Validate before calling

function isSafeLinkedinUrl(u) {
  try {
    const parsed = new URL(u);
    return parsed.protocol === 'https:' && !parsed.username && !parsed.password && !parsed.port &&
      (parsed.hostname === 'linkedin.com' || parsed.hostname === 'www.linkedin.com');
  } catch { return false; }
}
if (!isSafeLinkedinUrl(myUrl)) throw new Error('Provide an https www.linkedin.com URL');

Type guard

function isLinkedInHostUrl(v) {
  if (typeof v !== 'string') return false;
  try {
    const h = new URL(v).hostname.toLowerCase();
    return h === 'linkedin.com' || h === 'www.linkedin.com';
  } catch { return false; }
}

Try / catch

try {
  await url({ url: myUrl });
} catch (e) {
  if (e instanceof ArgumentError && /must point to linkedin\.com/.test(e.message)) {
    console.error('Use a canonical https://www.linkedin.com/... URL (expand short links).');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling assertSafeLinkedinUrl (directly or via the 'url' command) with a URL whose hostname is not linkedin.com or www.linkedin.com, e.g. 'https://linkedi.com/in/x', 'https://linkedin.evil.com', a short link like 'https://lnkd.in/abc', or an IP/other-domain host.

Common situations: Users pasting shortened LinkedIn share links (lnkd.in), mirror domains, locale subdomains like 'fr.linkedin.com', or typos in the hostname.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/9a446fdff0794c3c. Report an issue: GitHub.