webstudio-is / webstudio

The web builder for advanced sites. An open-source visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
https://webstudio.is
GNU Affero General Public License v3.0
4.55k stars 490 forks source link

Security issue, never initialize AuthorizationContext buildEnv with "prod" on SaaS and Self-hosted #968

Open istarkov opened 1 year ago

istarkov commented 1 year ago

Now at open-source previews | dev-mode we use Canvas to show production builds. And it reads project data from DB directly. That's why we have buildEnv parameter in the AuthorizationContext https://github.com/webstudio-is/webstudio-designer/blob/124ab25174ea9faca2290f6377038541b5f4cd8b/packages/trpc-interface/src/context/context.server.ts#L24-L27

If it is set to prod we allow view access to the project. If it ok for development and previews it's a security hole for SaaS/Self-Hosted projects, as allows to get access to all the sources of a project.

Now it's used in 2 places.

  1. To show production build on canvas at preview/development and not used at production (SaaS) from what I know https://github.com/webstudio-is/webstudio-designer/blob/124ab25174ea9faca2290f6377038541b5f4cd8b/apps/designer/app/routes/$.tsx#L55

  2. To clone project into KV storage at SaaS https://github.com/webstudio-is/webstudio-designer/blob/124ab25174ea9faca2290f6377038541b5f4cd8b/apps/designer/app/routes/rest/project.$projectId.tsx#L22

2nd case is used at SaaS now, but used by our worker and the endpoint can be protected with API KEY as its interservice communication.

What to do

istarkov commented 1 year ago

Probably we need some naming for prod context creation, like createContextWithBuildEnvProd_DO_NOT_USE_IT

istarkov commented 1 year ago

Also, as of now we don't have a working publish at opensource, probably it can be only development issue. In that case buildEnv can be a synonim of NODE_ENV !== "production"

rpominov commented 1 year ago

Maybe something like createViewAnyProjectContext if that's what it actually does?