isBlockedPath method

bool isBlockedPath(
  1. String path
)

Returns true if the path contains a blocked CID or IPNS name.

Accepts /ipfs/…, /ipns/…, ipfs://… and ipns://… forms and evaluates path-scoped rules (/ipfs/CID/PATH, PATH* prefixes, ! negations) as well as double-hash entries.

Implementation

bool isBlockedPath(String path) {
  if (!_config.enableDenylist) return false;
  var normalized = path.trim();
  final lower = normalized.toLowerCase();
  if (lower.startsWith('ipfs://')) {
    normalized = '/ipfs/${normalized.substring('ipfs://'.length)}';
  } else if (lower.startsWith('ipns://')) {
    normalized = '/ipns/${normalized.substring('ipns://'.length)}';
  }

  final segments = normalized.split('/').where((s) => s.isNotEmpty).toList();
  for (var i = 0; i + 1 < segments.length; i++) {
    final namespace = segments[i].toLowerCase();
    if (namespace != 'ipfs' && namespace != 'ipns') continue;
    final value = segments[i + 1];
    var subPath = segments.sublist(i + 2).join('/');
    // Unreachable: segments contain no '/' and are non-empty, so the
    // joined sub-path can never end with '/'. Kept defensively.
    // coverage:ignore-start
    while (subPath.endsWith('/')) {
      subPath = subPath.substring(0, subPath.length - 1);
    }
    // coverage:ignore-end
    final blocked = namespace == 'ipfs'
        ? _isBlockedIpfsItem(value, subPath)
        : _isBlockedIpnsItem(value, subPath);
    if (blocked) return true;
  }
  return false;
}