Language: JavaScript
Label: safe
CWE: CWE-918 \u2014 Server-Side Request Forgery (SSRF)
The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.

Code:
module.exports = async (ctx) => {
    if (!isValidHost(ctx.params.column)) {
        throw Error('Invalid column');
    }

    const url = `http://${ctx.params.column}.bio1000.com/${ctx.params.id}`;
    const res = await got.get(url);
    const $ = cheerio.load(res.data);
    const list = $('.excerpt-1').get();

    const out = await Promise.all(
        list.slice(0, 5).map(async (item) => {
            const $ = cheerio.load(item);
            const time = $('.meta').text();
            const title = $('header h2 a').attr('title');
            const partial = $('header h2 a').attr('href');
            const address = partial;
            const cache = await ctx.cache.get(address);
            if (cache) {
                return Promise.resolve(JSON.parse(cache));
            }
            const res = await got.get(address);
            const get = cheerio.load(res.data);
            const contents = get('.article-content').html();
            const single = {
                title,
                pubDate: time,
                description: contents,
                link: address,
                guid: address,
            };
            ctx.cache.set(address, JSON.stringify(single));
            return Promise.resolve(single);
        })
    );
    ctx.state.data = {
        title: '生物帮',
        link: url,
        item: out,
    };
};