{"record":{"id":"51cae7d399cdad70","repo":"DIYgod/RSSHub","slug":"invalid-site","errorCode":null,"errorMessage":"Invalid site","messagePattern":"Invalid site","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":503,"severity":"error","filePath":"lib/routes/dut/index.ts","lineNumber":44,"sourceCode":"订阅 **多级** 栏目如 [大连理工大学新闻网](https://news.dlut.edu.cn) 的 [人才培养](https://news.dlut.edu.cn/xwjj01/rcpy.htm) 分类栏目，同样分为 3 步：\n\n1. 将 URL \\`https://news.dlut.edu.cn/xwjj01/rcpy.htm\\` 中 \\`https://\\` 与 \\`.dlut.edu.cn/\\` 中间的 \\`news\\` 作为 \\`site\\` 参数填入；\n2. 把 \\`https://news.dlut.edu.cn/\\` 与 \\`.htm\\` 间 \\`xwjj01/rcpy\\` 作为 \\`category\\` 参数填入；\n3. 最终可获得 [\\`/dut/news/xwjj01/rcpy\\`](https://rsshub.app/dut/news/xwjj01/rcpy)。\n\n::: tip 小提示\n大连理工大学大部分站点支持上述通用规则进行订阅。下方的大连理工大学相关路由基本适用于该规则，在其对应的表格中没有提及的分类栏目，可以使用上方的方法自行扩展。\n:::\n\n::: tip 小小提示\n你会发现 [大连理工大学新闻网](https://news.dlut.edu.cn) 的 [人才培养](https://news.dlut.edu.cn/xwjj01/rcpy.htm) 分类栏目在下方 **新闻网** 参数表格中 \\`category\\` 参数为 \\`rcpy\\`，并非上面例子中给出的 \\`xwjj01/rcpy\\`。这意味着开发者对路由 \\`/dut/news/xwjj01/rcpy\\` 指定了快捷方式 \\`/dut/news/rcpy\\`。两者的效果是一致的。\n:::`,\n};\n\nasync function handler(ctx) {\n    const site = ctx.params[0] ?? 'news';\n    if (!isValidHost(site)) {\n        throw new InvalidParameterError('Invalid site');\n    }\n\n    let items;\n    let category = ctx.params[1] ?? (Object.hasOwn(defaults, site) ? defaults[site] : '');\n    category = Object.hasOwn(shortcuts, site) && Object.hasOwn(shortcuts[site], category) ? shortcuts[site][category] : category;\n\n    const rootUrl = `https://${site}.dlut.edu.cn`;\n    const currentUrl = `${rootUrl}/${category}.htm`;\n\n    const response = await got({\n        method: 'get',\n        url: currentUrl,\n    });\n\n    const $ = load(response.data);\n\n    if (site === 'panjin') {\n        items = $('a.news').slice(0, -4);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/dut/index.ts#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use only the subdomain portion as the site parameter: 'news' not 'https://news.dlut.edu.cn'.","Ensure the site parameter contains only valid hostname characters (letters, digits, hyphens).","If no site is provided, the default 'news' is used."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate that the site parameter is a valid hostname component\nfunction isValidDutSite(site: string): boolean {\n    // Must be a valid hostname label (alphanumeric, hyphens, dots)\n    return /^[a-zA-Z0-9][a-zA-Z0-9.-]*$/.test(site) && !site.includes('/') && !site.includes(':');\n}\n\nconst site = userInput || 'news';\nif (!isValidDutSite(site)) {\n    throw new Error(`Invalid site '${site}'. Use the subdomain portion only (e.g. 'news').`);\n}","typeGuard":"function isValidHostLabel(value: string): boolean {\n    return /^[a-zA-Z0-9]([a-zA-Z0-9.-]*[a-zA-Z0-9])?$/.test(value) && value.length <= 63;\n}","tryCatchPattern":"try {\n    const feed = await fetch(`${rsshubUrl}/dut/${site}/${category}`);\n} catch (e) {\n    if (e.message.includes('Invalid site')) {\n        console.error(`Site '${site}' contains invalid characters. Use subdomain only (e.g. 'news').`);\n    }\n    throw e;\n}","preventionTips":["Pass only the subdomain portion as the site parameter (e.g. 'news', not 'https://news.dlut.edu.cn').","Do not include paths, protocols, or ports in the site parameter.","If no site is needed, omit it — the default 'news' is used."],"tags":["dut","invalid-parameter","host-validation","university"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}