Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

651 B
Raw Blame
import { namesObjectBuiltIn } from '../skill/packageFiles';

/**
 * Normalizes package-relative skill paths and rejects unsafe path forms.
 *
 * Before:
 * - "references/../SKILL.md"
 *
 * After:
 * - Throws "path traversal is not allowed"
 */
export const assertPackageRelativePath = (path: string) => {
  if (path.startsWith('/')) throw new Error('absolute paths are not allowed');

  const segments = path.split('/').filter(Boolean);
  if (segments.includes('..')) {
    throw new Error('path traversal is not allowed');
  }
  if (namesObjectBuiltIn(path)) throw new Error('object built-in names are not allowed');

  return segments.join('/');
};