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 (!config.feature.allow_user_supply_unsafe_domain && !allowDomain.includes(ctx.params.domain)) {
        ctx.throw(403, `This RSS is disabled unless 'ALLOW_USER_SUPPLY_UNSAFE_DOMAIN' is set to 'true'.`);
    }

    const scheme = ctx.params.https || 'https';
    const cdn = config.wordpress.cdnUrl;

    const domain = `${scheme}://${ctx.params.domain}`;
    const feed = await parser.parseURL(`${domain}/feed/`);
    const items = await Promise.all(
        feed.items.map(async (item) => {
            const cache = await ctx.cache.get(item.link);
            if (cache) {
                return Promise.resolve(JSON.parse(cache));
            }
            const description =
                scheme === 'https' || !cdn
                    ? item['content:encoded']
                    : item['content:encoded'].replace(/(?<=<img.*src=")(.*)(?=".*\/>)/g, (match, p) => {
                          if (p[0] === '/') {
                              return cdn + feed.link + p;
                          } else if (p.slice(0, 5) === 'http:') {
                              return cdn + p;
                          } else {
                              return p;
                          }
                      });
            const article = {
                title: item.title,
                description,
                pubDate: item.pubDate,
                link: item.link,
                author: item.creator,
            };
            return Promise.resolve(article);
        })
    );

    ctx.state.data = {
        title: feed.title,
        link: feed.link,
        description: feed.description,
        item: items,
    };
};