Skip to content

fix(router): securely check path for proper destination #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MegaManSec
Copy link

The router previously checked whether a path contained a route key. This check was insufficient, as it allowed a route configured as such:
'/admin': 'http://localhost:4002',
to be accessed to be accessible by requesting /some/public/path?q=/admin, which would match and route the request to localhost:4002.

If http-proxy-middleware is in front of a firewall which restricts access to /admin, this could have allowed unauthorized access to the admin route.


Given the following options:

const proxyOptions = {
  target: 'http://localhost:4001',
  changeOrigin: true,
  router: {
    '/admin': 'http://localhost:4002',
  },
  on: {
    proxyReq: (proxyReq, req, res) => {
      const targetHost = proxyReq.host;
      console.log(`[PROXY] Request for "${req.originalUrl}" is being routed to -> ${targetHost}`);
    },
  },
};

const proxy = createProxyMiddleware(proxyOptions);

it was previously possible to run curl 'http://localhost:3000/some/public/path?q=/admin to access the /admin endpoint.

How has this been tested?

Added testcases + manually.

  • Bug fix (non-breaking change which fixes an issue)

The router previously checked whether a path contained a route key. This check
was insufficient, as it allowed a route configured as such:
    '/admin': 'http://localhost:4002',
to be accessed to be accessible by requesting `/some/public/path?q=/admin`,
which would match and route the request to localhost:4002.

If http-proxy-middleware is in front of a firewall which restricts access to
/admin, this could have allowed unauthorized access to the admin route.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant