Browse Source

feat: add user page access control based on disableUserPages setting

Shun Miyazawa 2 months ago
parent
commit
68fb81ada4
1 changed files with 25 additions and 0 deletions
  1. 25 0
      apps/app/src/pages/share/[[...path]]/page-data-props.ts

+ 25 - 0
apps/app/src/pages/share/[[...path]]/page-data-props.ts

@@ -1,6 +1,10 @@
 import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
 import type { IPage } from '@growi/core';
 import { getIdStringForRef } from '@growi/core';
+import {
+  isUserPage,
+  isUsersTopPage,
+} from '@growi/core/dist/utils/page-path-utils';
 import type { model } from 'mongoose';
 
 import type { CrowiRequest } from '~/interfaces/crowi-request';
@@ -68,6 +72,27 @@ export const getPageDataForInitial = async (
     return notFoundProps;
   }
 
+  const disableUserPages = configManager.getConfig('security:disableUserPages');
+  if (disableUserPages) {
+    const pagePath = pageWithMeta.data.path;
+    if (isUserPage(pagePath) || isUsersTopPage(pagePath)) {
+      return {
+        props: {
+          isNotFound: true,
+          pageWithMeta: {
+            data: null,
+            meta: {
+              isNotFound: true,
+              isForbidden: true,
+            },
+          },
+          isExpired: undefined,
+          shareLink: undefined,
+        },
+      };
+    }
+  }
+
   // expired
   if (shareLink.isExpired()) {
     const populatedPage =