DIYgod/RSSHub · error · InvalidParameterError
Invalid id
Error message
Invalid id
What it means
An `InvalidParameterError` from the zhubai route when the `:id` path parameter fails `isValidHost`. The `id` is used both as the publication subdomain (`https://${id}.zhubai.love`) and in the API URL, so it must be a valid DNS host label; anything else is rejected before any request is made.
Source
Thrown at lib/routes/zhubai/index.ts:32
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '文章',
maintainers: ['naixy28'],
handler,
description: `::: tip
在路由末尾处加上 \`?limit=限制获取数目\` 来限制获取条目数量,默认值为\`20\`
:::`,
};
async function handler(ctx) {
const id = ctx.req.param('id');
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 20;
if (!isValidHost(id)) {
throw new InvalidParameterError('Invalid id');
}
const response = await got({
method: 'get',
url: `https://${id}.zhubai.love/api/publications/${id}/posts?publication_id_type=token&limit=${limit}`,
headers: {
Referer: `https://${id}.zhubai.love/`,
},
});
const data = response.data.data;
const { name, description } = data[0].publication;
return {
title: name,
link: `https://${id}.zhubai.love/`,
description,
item: data.map((item) => ({
title: item.title,View on GitHub (pinned to bed535e087)
Solutions
- Pass only the bare publication subdomain token, e.g. `/zhubai/mypublication`.
- If you have the full site URL, extract the subdomain segment (`foo` from `foo.zhubai.love`) before calling the route.
- Strip protocol, trailing path, and dots from the value before using it as `id`.
Example fix
// before — full URL passed // GET /zhubai/https://foo.zhubai.love -> Invalid id // after — bare subdomain token // GET /zhubai/foo
Defensive patterns
Strategy: validation
Validate before calling
function normalizeZhubaiId(raw) {
let id = raw.replace(/^https?:\/\//, '').replace(/\.zhubai\.love.*$/, '').replace(/\/$/, '');
if (!/^[a-z0-9-]+$/i.test(id)) {
throw new Error(`Invalid zhubai id: ${raw}`);
}
return id;
} Type guard
function isValidZhubaiId(id: string): boolean {
return /^[a-z0-9-]+$/i.test(id);
} Prevention
- Validate the id is a clean host label before building the subdomain/API URL.
- Strip protocol and domain suffix when accepting pasted URLs.
- Reject values containing dots, slashes, or spaces early.
When it happens
Trigger: The caller passes an `id` that is not a valid hostname label — contains dots, slashes, spaces, protocol, or special characters; e.g. someone pastes a full URL or an email-like value instead of the bare publication token.
Common situations: User copies `https://foo.zhubai.love` or `foo.zhubai.love` instead of just `foo`; a malformed request injects path separators; the publication token was mistyped with invalid characters.
Related errors
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/280fe0a3d485b869.
Report an issue: GitHub.