fastify/fastify-http-proxy

upstream option does not support port like 80

s524797336 opened this issue · 4 comments

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

3.21.6

Plugin version

6.2.0

Node.js version

16.6.2

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

10.15.7

Description

If upstream set web port like 80 etc, the fastify-reply-from will throw error say source must be a relative path string, cause

// dest.href is 'http://xxx/xx'
// reqBase is 'http://xxx:80/'
dest.href.startsWith(reqBase) // witch is false

Steps to Reproduce

import proxy from 'fastify-http-proxy'
const app = fastify()
app.register(proxy, {
      upstream: 'http://xxx:80',
      prefix: '/xx',
})

Expected Behavior

Should handle 80 port as no port

Eomm commented

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

This is due to:

const url =  new URL('http://google.it:80').toString()
// url is 'http://google.it/'

I think we should do some more sanitization of inputs as they get inside the plugin.

I will try to solve this in this week, when i got time

Upgrade fastify-reply-from to 6.4.0 solve this