Language: TypeScript
Label: vulnerable
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:
                person_created_at: DateTime.fromISO(now).toUTC(),
            } as any)
            expect(fetch).toHaveBeenCalledWith('https://example.com/', {
                body: JSON.stringify(
                    {
                        hook: {
                            id: 'id',
                            event: 'foo',
                            target: 'https://example.com/',
                        },
                        data: {
                            event: 'foo',
                            teamId: hook.team_id,
                            person: {
                                uuid: uuid,
                                properties: { foo: 'bar' },
                                created_at: now,
                            },
                        },
                    },
                    undefined,
                    4
                ),
                headers: { 'Content-Type': 'application/json' },
                method: 'POST',
                timeout: 20000,
            })
        })

        test('private IP hook allowed on self-hosted', async () => {
            await hookCommander.postRestHook({ ...hook, target: 'http://127.0.0.1' }, { event: 'foo' } as any)

            expect(fetch).toHaveBeenCalledWith('http://127.0.0.1', expect.anything())
        })

        test('private IP hook forbidden on Cloud', async () => {
            jest.mocked(isCloud).mockReturnValue(true)

            await expect(
                hookCommander.postRestHook({ ...hook, target: 'http://127.0.0.1' }, { event: 'foo' } as any)
            ).rejects.toThrow(new FetchError('Internal hostname', 'posthog-host-guard'))
        })
    })