Jelajahi Sumber

Merge pull request #7172 from weseek/feat/109648-use-configured-xss-custom-whitelist

feat: Use configured xss custom whitelist
Yuki Takei 3 tahun lalu
induk
melakukan
0e020850b2

+ 12 - 7
packages/app/src/components/Admin/MarkdownSetting/WhiteListInput.jsx

@@ -2,9 +2,9 @@ import React from 'react';
 
 
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
+import { defaultSchema as sanitizeDefaultSchema } from 'rehype-sanitize';
 
 
 import AdminMarkDownContainer from '~/client/services/AdminMarkDownContainer';
 import AdminMarkDownContainer from '~/client/services/AdminMarkDownContainer';
-import { tags, attrs } from '~/services/xss/recommended-whitelist';
 
 
 import { withUnstatedContainers } from '../../UnstatedUtils';
 import { withUnstatedContainers } from '../../UnstatedUtils';
 
 
@@ -16,18 +16,21 @@ class WhiteListInput extends React.Component {
     this.tagWhiteList = React.createRef();
     this.tagWhiteList = React.createRef();
     this.attrWhiteList = React.createRef();
     this.attrWhiteList = React.createRef();
 
 
+    this.tags = sanitizeDefaultSchema.tagNames;
+    this.attrs = JSON.stringify(sanitizeDefaultSchema.attributes);
+
     this.onClickRecommendTagButton = this.onClickRecommendTagButton.bind(this);
     this.onClickRecommendTagButton = this.onClickRecommendTagButton.bind(this);
     this.onClickRecommendAttrButton = this.onClickRecommendAttrButton.bind(this);
     this.onClickRecommendAttrButton = this.onClickRecommendAttrButton.bind(this);
   }
   }
 
 
   onClickRecommendTagButton() {
   onClickRecommendTagButton() {
-    this.tagWhiteList.current.value = tags;
-    this.props.adminMarkDownContainer.setState({ tagWhiteList: tags });
+    // this.tagWhiteList.current.value = this.tags;
+    // this.props.adminMarkDownContainer.setState({ tagWhiteList: this.tags });
   }
   }
 
 
   onClickRecommendAttrButton() {
   onClickRecommendAttrButton() {
-    this.attrWhiteList.current.value = attrs;
-    this.props.adminMarkDownContainer.setState({ attrWhiteList: attrs });
+    // this.attrWhiteList.current.value = this.attrs;
+    // this.props.adminMarkDownContainer.setState({ attrWhiteList: this.attrs });
   }
   }
 
 
   render() {
   render() {
@@ -38,11 +41,12 @@ class WhiteListInput extends React.Component {
         <div className="mt-4">
         <div className="mt-4">
           <div className="d-flex justify-content-between">
           <div className="d-flex justify-content-between">
             {t('markdown_settings.xss_options.tag_names')}
             {t('markdown_settings.xss_options.tag_names')}
-            <p id="btn-import-tags" className="btn btn-sm btn-primary mb-0" onClick={this.onClickRecommendTagButton}>
+            <p id="btn-import-tags" className="btn btn-sm btn-primary mb-0 disabled" onClick={this.onClickRecommendTagButton}>
               {t('markdown_settings.xss_options.import_recommended', { target: 'Tags' })}
               {t('markdown_settings.xss_options.import_recommended', { target: 'Tags' })}
             </p>
             </p>
           </div>
           </div>
           <textarea
           <textarea
+            disabled
             className="form-control xss-list"
             className="form-control xss-list"
             name="recommendedTags"
             name="recommendedTags"
             rows="6"
             rows="6"
@@ -55,11 +59,12 @@ class WhiteListInput extends React.Component {
         <div className="mt-4">
         <div className="mt-4">
           <div className="d-flex justify-content-between">
           <div className="d-flex justify-content-between">
             {t('markdown_settings.xss_options.tag_attributes')}
             {t('markdown_settings.xss_options.tag_attributes')}
-            <p id="btn-import-tags" className="btn btn-sm btn-primary mb-0" onClick={this.onClickRecommendAttrButton}>
+            <p id="btn-import-tags" className="btn btn-sm btn-primary mb-0 disabled" onClick={this.onClickRecommendAttrButton}>
               {t('markdown_settings.xss_options.import_recommended', { target: 'Attrs' })}
               {t('markdown_settings.xss_options.import_recommended', { target: 'Attrs' })}
             </p>
             </p>
           </div>
           </div>
           <textarea
           <textarea
+            disabled
             className="form-control xss-list"
             className="form-control xss-list"
             name="recommendedAttrs"
             name="recommendedAttrs"
             rows="6"
             rows="6"

+ 4 - 1
packages/app/src/components/Admin/MarkdownSetting/XssForm.jsx

@@ -93,6 +93,7 @@ class XssForm extends React.Component {
           <div className="col-md-6 col-sm-12 align-self-start mb-4">
           <div className="col-md-6 col-sm-12 align-self-start mb-4">
             <div className="custom-control custom-radio">
             <div className="custom-control custom-radio">
               <input
               <input
+                disabled
                 type="radio"
                 type="radio"
                 className="custom-control-input"
                 className="custom-control-input"
                 id="xssOption2"
                 id="xssOption2"
@@ -101,7 +102,9 @@ class XssForm extends React.Component {
                 onChange={() => { adminMarkDownContainer.setState({ xssOption: RehypeSanitizeOption.CUSTOM }) }}
                 onChange={() => { adminMarkDownContainer.setState({ xssOption: RehypeSanitizeOption.CUSTOM }) }}
               />
               />
               <label className="custom-control-label w-100" htmlFor="xssOption2">
               <label className="custom-control-label w-100" htmlFor="xssOption2">
-                <p className="font-weight-bold">{t('markdown_settings.xss_options.custom_whitelist')}</p>
+                <p className="font-weight-bold">{t('markdown_settings.xss_options.custom_whitelist')}
+                  <span className='text-warning'> (TBD: Currently unavailable)</span>
+                </p>
                 <WhiteListInput customizable />
                 <WhiteListInput customizable />
               </label>
               </label>
             </div>
             </div>

+ 0 - 5
packages/app/src/interfaces/rehype.ts

@@ -4,8 +4,3 @@ export const RehypeSanitizeOption = {
 } as const;
 } as const;
 
 
 export type RehypeSanitizeOption = typeof RehypeSanitizeOption[keyof typeof RehypeSanitizeOption];
 export type RehypeSanitizeOption = typeof RehypeSanitizeOption[keyof typeof RehypeSanitizeOption];
-
-export type RehypeSanitizeOptionConfig = {
-  isEnabledXssPrevention: boolean,
-  // Todo add types for custom sanitize option at https://redmine.weseek.co.jp/issues/109763
-}

+ 1 - 4
packages/app/src/interfaces/services/renderer.ts

@@ -1,8 +1,5 @@
 import { XssOptionConfig } from '~/services/xss/xssOption';
 import { XssOptionConfig } from '~/services/xss/xssOption';
 
 
-import { RehypeSanitizeOptionConfig } from '../rehype';
-
-
 export type RendererConfig = {
 export type RendererConfig = {
   isEnabledLinebreaks: boolean,
   isEnabledLinebreaks: boolean,
   isEnabledLinebreaksInComments: boolean,
   isEnabledLinebreaksInComments: boolean,
@@ -12,4 +9,4 @@ export type RendererConfig = {
 
 
   plantumlUri: string | null,
   plantumlUri: string | null,
   blockdiagUri: string | null,
   blockdiagUri: string | null,
-} & XssOptionConfig & RehypeSanitizeOptionConfig;
+} & XssOptionConfig;

+ 1 - 1
packages/app/src/pages/_private-legacy-pages.page.tsx

@@ -135,7 +135,7 @@ async function injectServerConfigurations(context: GetServerSidePropsContext, pr
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
 
 
     // XSS Options
     // XSS Options
-    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),

+ 1 - 1
packages/app/src/pages/_search.page.tsx

@@ -154,7 +154,7 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
 
 
     // XSS Options
     // XSS Options
-    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),

+ 3 - 3
packages/app/src/pages/me/[[...path]].page.tsx

@@ -3,7 +3,7 @@ import React, { useMemo } from 'react';
 import { IUserHasId } from '@growi/core';
 import { IUserHasId } from '@growi/core';
 import { model as mongooseModel } from 'mongoose';
 import { model as mongooseModel } from 'mongoose';
 import {
 import {
-  NextPage, GetServerSideProps, GetServerSidePropsContext,
+  GetServerSideProps, GetServerSidePropsContext,
 } from 'next';
 } from 'next';
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
 import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
@@ -28,10 +28,10 @@ import {
 } from '~/stores/ui';
 } from '~/stores/ui';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
+import { NextPageWithLayout } from '../_app.page';
 import {
 import {
   CommonProps, getNextI18NextConfig, getServerSideCommonProps, generateCustomTitle,
   CommonProps, getNextI18NextConfig, getServerSideCommonProps, generateCustomTitle,
 } from '../utils/commons';
 } from '../utils/commons';
-import { NextPageWithLayout } from '../_app.page';
 
 
 
 
 const logger = loggerFactory('growi:pages:me');
 const logger = loggerFactory('growi:pages:me');
@@ -185,7 +185,7 @@ async function injectServerConfigurations(context: GetServerSidePropsContext, pr
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
 
 
     // XSS Options
     // XSS Options
-    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),

+ 1 - 1
packages/app/src/pages/share/[[...path]].page.tsx

@@ -170,7 +170,7 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
 
 
     // XSS Options
     // XSS Options
-    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'),
     attrWhiteList: xssService.getAttrWhiteList(),
     attrWhiteList: xssService.getAttrWhiteList(),
     tagWhiteList: xssService.getTagWhiteList(),
     tagWhiteList: xssService.getTagWhiteList(),
     highlightJsStyleBorder: configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
     highlightJsStyleBorder: configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),

+ 2 - 2
packages/app/src/pages/tags.page.tsx

@@ -25,10 +25,10 @@ import {
   useIsSearchScopeChildrenAsDefault, useRendererConfig,
   useIsSearchScopeChildrenAsDefault, useRendererConfig,
 } from '../stores/context';
 } from '../stores/context';
 
 
+import { NextPageWithLayout } from './_app.page';
 import {
 import {
   CommonProps, getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle,
   CommonProps, getServerSideCommonProps, getNextI18NextConfig, generateCustomTitle,
 } from './utils/commons';
 } from './utils/commons';
-import { NextPageWithLayout } from './_app.page';
 
 
 const PAGING_LIMIT = 10;
 const PAGING_LIMIT = 10;
 
 
@@ -164,7 +164,7 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
 
 
     // XSS Options
     // XSS Options
-    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),

+ 1 - 1
packages/app/src/pages/trash.page.tsx

@@ -156,7 +156,7 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
     blockdiagUri: process.env.BLOCKDIAG_URI ?? null,
 
 
     // XSS Options
     // XSS Options
-    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:xss:isEnabledPrevention'),
+    isEnabledXssPrevention: configManager.getConfig('markdown', 'markdown:rehypeSanitize:isEnabledPrevention'),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     attrWhiteList: crowi.xssService.getAttrWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     tagWhiteList: crowi.xssService.getTagWhiteList(),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),
     highlightJsStyleBorder: crowi.configManager.getConfig('crowi', 'customize:highlightJsStyleBorder'),