DIYgod/RSSHub · warning · InvalidParameterError

Invalid host

Error message

Invalid host

What it means

Thrown as an `InvalidParameterError` when either the `cate` or `language` path parameter fails `isValidHost()`, which checks the value against the regex `/^[\dA-Z](?:[\dA-Z-]{0,61}[\dA-Z])?$/i`. This rejects strings containing dots, underscores, spaces, or other characters not valid in a DNS hostname label. The check exists because the values are interpolated directly into a URL hostname: `https://${language}.eagle.cool`.

Source

Thrown at lib/routes/eagle/blog.ts:52

        supportScihub: false,
    },
    radar: [
        {
            source: ['cn.eagle.cool/blog'],
            target: '/blog',
        },
    ],
    name: 'Blog',
    maintainers: ['Fatpandac'],
    handler,
    url: 'cn.eagle.cool/blog',
};

async function handler(ctx) {
    let cate = ctx.req.param('cate') ?? 'all';
    let language = ctx.req.param('language') ?? 'cn';
    if (!isValidHost(cate) || !isValidHost(language)) {
        throw new InvalidParameterError('Invalid host');
    }
    if (!cateList.has(cate)) {
        language = cate;
        cate = 'all';
    }

    const host = `https://${language}.eagle.cool`;
    const url = `${host}/blog/${cate === 'all' ? '' : cate}`;

    const response = await got(url);
    const $ = load(response.data);
    const title = $('div.categories-list > div > div > div > ul > li.active').text();
    const list = $('div.post-item')
        .toArray()
        .map((item): DataItem & { link: string } => ({
            title: $(item).find('div.title').text(),
            link: new URL($(item).find('a').attr('href')!, host).href,
            pubDate: parseDate($(item).find('div.metas > a > span').text().replace('・', '')),

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only hostname-safe values: alphanumeric characters and hyphens. Valid languages are `cn`, `tw`, `en`.
  2. If omitting parameters, use the route with no path segments: `/eagle/blog`.
  3. Check the cateList Set (`all`, `design-resources`, `learn-design`, `inside-eagle`) for valid category slugs.
Defensive patterns

Strategy: validation

Validate before calling

import { isValidHost } from '@/utils/valid-host';

function validateEagleParams(cate: string, language: string): void {
    if (!isValidHost(cate) || !isValidHost(language)) {
        throw new InvalidParameterError('Parameters must be hostname-safe (alphanumeric and hyphens only)');
    }
}

Type guard

function isValidHostSegment(value: string | undefined): boolean {
    if (typeof value !== 'string') return false;
    return /^[\dA-Z](?:[\dA-Z-]{0,61}[\dA-Z])?$/i.test(value);
}

Prevention

When it happens

Trigger: A user passes a parameter containing characters outside the hostname-safe set — e.g., `cate` = `design.resources` (dot), `language` = `zh_cn` (underscore), or `cate` = `` (empty after trimming). The regex test fails and the error fires before any network request.

Common situations: User passes a URL-encoded or malformed category slug. The language parameter is omitted but the cate parameter is also omitted, and the default falls through. A malicious or accidental parameter contains path traversal characters.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/47cda6c2e7282761. Report an issue: GitHub.