DIYgod/RSSHub · error · InvalidParameterError

Invalid site

Error message

Invalid site

What it means

Thrown by the DUT (Dalian University of Technology) generic route when the `site` path parameter fails the `isValidHost()` check. The route constructs `https://<site>.dlut.edu.cn` from this parameter, so it must be a valid hostname component (alphanumeric, hyphens, dots). `isValidHost` rejects strings containing invalid hostname characters (e.g. slashes, colons, spaces) that could cause malformed URLs or path traversal.

Source

Thrown at lib/routes/dut/index.ts:44

订阅 **多级** 栏目如 [大连理工大学新闻网](https://news.dlut.edu.cn) 的 [人才培养](https://news.dlut.edu.cn/xwjj01/rcpy.htm) 分类栏目,同样分为 3 步:

1. 将 URL \`https://news.dlut.edu.cn/xwjj01/rcpy.htm\` 中 \`https://\` 与 \`.dlut.edu.cn/\` 中间的 \`news\` 作为 \`site\` 参数填入;
2. 把 \`https://news.dlut.edu.cn/\` 与 \`.htm\` 间 \`xwjj01/rcpy\` 作为 \`category\` 参数填入;
3. 最终可获得 [\`/dut/news/xwjj01/rcpy\`](https://rsshub.app/dut/news/xwjj01/rcpy)。

::: tip 小提示
大连理工大学大部分站点支持上述通用规则进行订阅。下方的大连理工大学相关路由基本适用于该规则,在其对应的表格中没有提及的分类栏目,可以使用上方的方法自行扩展。
:::

::: tip 小小提示
你会发现 [大连理工大学新闻网](https://news.dlut.edu.cn) 的 [人才培养](https://news.dlut.edu.cn/xwjj01/rcpy.htm) 分类栏目在下方 **新闻网** 参数表格中 \`category\` 参数为 \`rcpy\`,并非上面例子中给出的 \`xwjj01/rcpy\`。这意味着开发者对路由 \`/dut/news/xwjj01/rcpy\` 指定了快捷方式 \`/dut/news/rcpy\`。两者的效果是一致的。
:::`,
};

async function handler(ctx) {
    const site = ctx.params[0] ?? 'news';
    if (!isValidHost(site)) {
        throw new InvalidParameterError('Invalid site');
    }

    let items;
    let category = ctx.params[1] ?? (Object.hasOwn(defaults, site) ? defaults[site] : '');
    category = Object.hasOwn(shortcuts, site) && Object.hasOwn(shortcuts[site], category) ? shortcuts[site][category] : category;

    const rootUrl = `https://${site}.dlut.edu.cn`;
    const currentUrl = `${rootUrl}/${category}.htm`;

    const response = await got({
        method: 'get',
        url: currentUrl,
    });

    const $ = load(response.data);

    if (site === 'panjin') {
        items = $('a.news').slice(0, -4);

View on GitHub (pinned to bed535e087)

Solutions

  1. Use only the subdomain portion as the site parameter: 'news' not 'https://news.dlut.edu.cn'.
  2. Ensure the site parameter contains only valid hostname characters (letters, digits, hyphens).
  3. If no site is provided, the default 'news' is used.
Defensive patterns

Strategy: validation

Validate before calling

// Validate that the site parameter is a valid hostname component
function isValidDutSite(site: string): boolean {
    // Must be a valid hostname label (alphanumeric, hyphens, dots)
    return /^[a-zA-Z0-9][a-zA-Z0-9.-]*$/.test(site) && !site.includes('/') && !site.includes(':');
}

const site = userInput || 'news';
if (!isValidDutSite(site)) {
    throw new Error(`Invalid site '${site}'. Use the subdomain portion only (e.g. 'news').`);
}

Type guard

function isValidHostLabel(value: string): boolean {
    return /^[a-zA-Z0-9]([a-zA-Z0-9.-]*[a-zA-Z0-9])?$/.test(value) && value.length <= 63;
}

Try / catch

try {
    const feed = await fetch(`${rsshubUrl}/dut/${site}/${category}`);
} catch (e) {
    if (e.message.includes('Invalid site')) {
        console.error(`Site '${site}' contains invalid characters. Use subdomain only (e.g. 'news').`);
    }
    throw e;
}

Prevention

When it happens

Trigger: The site parameter contains characters invalid for a hostname (e.g. 'news/ttgz' with a slash, 'news:8080' with a colon, or an empty string after fallback); the user accidentally included the full URL or protocol in the site parameter.

Common situations: User supplies 'https://news.dlut.edu.cn' as the site instead of just 'news'; user includes a path component in the site parameter; the route's wildcard path matching captures unexpected segments.

Related errors


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