vuestorefront / vue-storefront

Alokai is a Frontend as a Service solution that simplifies composable commerce. It connects all the technologies needed to build and deploy fast & scalable ecommerce frontends. It guides merchants to deliver exceptional customer experiences quickly and easily.
https://www.alokai.com
MIT License
10.64k stars 2.09k forks source link

fix: integration api call security issue #6815

Closed bartoszherba closed 2 years ago

bartoszherba commented 2 years ago

Description

During debugging another issue with CT env, I found out that it's pretty easy to take down our middleware.e.g. let's get a real endpoint like: POST https://sapcc-dev.europe-west1.gcp.storefrontcloud.io/api/sapcc/addCartEntry . Wheresapcc is the integration of our middleware but let's send a request to some not existing integration, replace sapcc with something and the request will take down the node.js app

K8s will restart the app fastly but it shouldn’t work like that.

Here is a code responsible for the issue:

  app.post('/:integrationName/:functionName', async (req: Request, res: Response) => {
    const { integrationName, functionName } = req.params as any as RequestParams;
    const { apiClient, configuration, extensions, customQueries, initConfig } = integrations[integrationName];
    const middlewareContext: MiddlewareContext = { req, res, extensions, customQueries };
    const createApiClient = apiClient.createApiClient.bind({ middleware: middlewareContext });
    const apiClientInstance = createApiClient({ ...configuration, ...initConfig });
    const apiFunction = apiClientInstance.api[functionName];
    try {
      const platformResponse = await apiFunction(...req.body);
      res.send(platformResponse);
    } catch (error) {
      res.status(getAgnosticStatusCode(error));
      res.send(error);
    }
  });

We are looking for properties in integrations[integrationName] but they might be undefined. We have to add an additional check for that.

The bug happens only if middleware is deployed separately from the Nuxt app. E.g. run it via node middleware.js. I can kill e.g. sapcc-dev instance this way.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots:

Types of changes

Checklist:

Changelog

Tests

Code standards

Docs