Skip to content
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

chore: infrastructure upgrade #13892

Draft
wants to merge 454 commits into
base: main
Choose a base branch
from
Draft

chore: infrastructure upgrade #13892

wants to merge 454 commits into from

Conversation

iamjoel
Copy link
Collaborator

@iamjoel iamjoel commented Feb 18, 2025

Summary

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Tip

Close issue syntax: Fixes #<issue number> or Resolves #<issue number>, see documentation for more details.

Screenshots

Before After
... ...

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

<Link target="_blank" href={`${MARKETPLACE_URL_PREFIX}`} className='inline-flex items-center system-sm-medium text-text-accent'>
<div className='mb-2 flex items-center pt-2'>
<span className='text-text-tertiary system-sm-regular pr-1'>{t('common.modelProvider.discoverMore')}</span>
<Link target="_blank" href={`${MARKETPLACE_URL_PREFIX}`} className='system-sm-medium text-text-accent inline-flex items-center'>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 5 days ago

To fix the problem, we need to ensure that the MARKETPLACE_URL_PREFIX is properly sanitized before being used in the href attribute. This can be achieved by validating the URL to ensure it is safe and does not contain any malicious content.

The best way to fix this issue without changing existing functionality is to use a well-known library like DOMPurify to sanitize the URL. This will ensure that any potentially harmful content is removed before the URL is used.

Suggested changeset 2
web/app/components/header/account-setting/model-provider-page/index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx
--- a/web/app/components/header/account-setting/model-provider-page/index.tsx
+++ b/web/app/components/header/account-setting/model-provider-page/index.tsx
@@ -34,2 +34,3 @@
 import { MARKETPLACE_URL_PREFIX } from '@/config'
+import DOMPurify from 'dompurify'
 import cn from '@/utils/classnames'
@@ -167,3 +168,3 @@
             <span className='text-text-tertiary system-sm-regular pr-1'>{t('common.modelProvider.discoverMore')}</span>
-            <Link target="_blank" href={`${MARKETPLACE_URL_PREFIX}`} className='system-sm-medium text-text-accent inline-flex items-center'>
+            <Link target="_blank" href={DOMPurify.sanitize(`${MARKETPLACE_URL_PREFIX}`)} className='system-sm-medium text-text-accent inline-flex items-center'>
               {t('plugin.marketplace.difyMarketplace')}
EOF
@@ -34,2 +34,3 @@
import { MARKETPLACE_URL_PREFIX } from '@/config'
import DOMPurify from 'dompurify'
import cn from '@/utils/classnames'
@@ -167,3 +168,3 @@
<span className='text-text-tertiary system-sm-regular pr-1'>{t('common.modelProvider.discoverMore')}</span>
<Link target="_blank" href={`${MARKETPLACE_URL_PREFIX}`} className='system-sm-medium text-text-accent inline-flex items-center'>
<Link target="_blank" href={DOMPurify.sanitize(`${MARKETPLACE_URL_PREFIX}`)} className='system-sm-medium text-text-accent inline-flex items-center'>
{t('plugin.marketplace.difyMarketplace')}
web/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/package.json b/web/package.json
--- a/web/package.json
+++ b/web/package.json
@@ -122,3 +122,4 @@
         "zundo": "^2.1.0",
-        "zustand": "^4.5.2"
+        "zustand": "^4.5.2",
+        "dompurify": "^3.2.4"
     },
EOF
@@ -122,3 +122,4 @@
"zundo": "^2.1.0",
"zustand": "^4.5.2"
"zustand": "^4.5.2",
"dompurify": "^3.2.4"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.4 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
<Button
variant='primary'
className='w-[calc(50%-4px)]'
onClick={showInstallFromMarketplace}
>
{t('plugin.detailPanel.operation.install')}
</Button>
<a href={`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`} target='_blank' className='block flex-1 shrink-0 w-[calc(50%-4px)]'>
<a href={`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 5 days ago

To fix the problem, we need to ensure that the URL used in the href attribute is properly sanitized to prevent XSS attacks. One way to achieve this is by using a library like DOMPurify to sanitize the URL before using it. This will ensure that any potentially harmful content is removed from the URL.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the relevant file.
  3. Use DOMPurify to sanitize the URL before using it in the href attribute.
Suggested changeset 2
web/app/components/plugins/marketplace/list/card-wrapper.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/app/components/plugins/marketplace/list/card-wrapper.tsx b/web/app/components/plugins/marketplace/list/card-wrapper.tsx
--- a/web/app/components/plugins/marketplace/list/card-wrapper.tsx
+++ b/web/app/components/plugins/marketplace/list/card-wrapper.tsx
@@ -12,2 +12,3 @@
 import { useTags } from '@/app/components/plugins/hooks'
+import DOMPurify from 'dompurify'
 
@@ -57,3 +58,3 @@
               </Button>
-              <a href={`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'>
+              <a href={DOMPurify.sanitize(`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`)} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'>
                 <Button
@@ -85,3 +86,3 @@
       className='group relative inline-block cursor-pointer rounded-xl'
-      href={getPluginLinkInMarketplace(plugin)}
+      href={DOMPurify.sanitize(getPluginLinkInMarketplace(plugin))}
     >
EOF
@@ -12,2 +12,3 @@
import { useTags } from '@/app/components/plugins/hooks'
import DOMPurify from 'dompurify'

@@ -57,3 +58,3 @@
</Button>
<a href={`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'>
<a href={DOMPurify.sanitize(`${getPluginLinkInMarketplace(plugin)}?language=${localeFromLocale}`)} target='_blank' className='block w-[calc(50%-4px)] flex-1 shrink-0'>
<Button
@@ -85,3 +86,3 @@
className='group relative inline-block cursor-pointer rounded-xl'
href={getPluginLinkInMarketplace(plugin)}
href={DOMPurify.sanitize(getPluginLinkInMarketplace(plugin))}
>
web/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/package.json b/web/package.json
--- a/web/package.json
+++ b/web/package.json
@@ -122,3 +122,4 @@
         "zundo": "^2.1.0",
-        "zustand": "^4.5.2"
+        "zustand": "^4.5.2",
+        "dompurify": "^3.2.4"
     },
EOF
@@ -122,3 +122,4 @@
"zundo": "^2.1.0",
"zustand": "^4.5.2"
"zustand": "^4.5.2",
"dompurify": "^3.2.4"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.4 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
>{t('plugin.detailPanel.operation.checkUpdate')}</div>
)}
{(source === PluginSource.marketplace || source === PluginSource.github) && (
<a href={detailUrl} target='_blank' className='flex items-center px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'>
<a href={detailUrl} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover flex cursor-pointer items-center rounded-lg px-3 py-1.5'>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 6 days ago

To fix the problem, we need to ensure that the detailUrl is properly sanitized before being used in the anchor tag's href attribute. This can be achieved by using a library like DOMPurify to sanitize the URL and prevent any malicious scripts from being executed.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the relevant file.
  3. Use DOMPurify to sanitize the detailUrl before using it in the anchor tag.
Suggested changeset 2
web/app/components/plugins/plugin-detail-panel/operation-dropdown.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/app/components/plugins/plugin-detail-panel/operation-dropdown.tsx b/web/app/components/plugins/plugin-detail-panel/operation-dropdown.tsx
--- a/web/app/components/plugins/plugin-detail-panel/operation-dropdown.tsx
+++ b/web/app/components/plugins/plugin-detail-panel/operation-dropdown.tsx
@@ -14,2 +14,3 @@
 import cn from '@/utils/classnames'
+import DOMPurify from 'dompurify'
 
@@ -42,2 +43,4 @@
 
+  const sanitizedDetailUrl = DOMPurify.sanitize(detailUrl)
+
   return (
@@ -80,3 +83,3 @@
           {(source === PluginSource.marketplace || source === PluginSource.github) && (
-            <a href={detailUrl} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover flex cursor-pointer items-center rounded-lg px-3 py-1.5'>
+            <a href={sanitizedDetailUrl} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover flex cursor-pointer items-center rounded-lg px-3 py-1.5'>
               <span className='grow'>{t('plugin.detailPanel.operation.viewDetail')}</span>
EOF
@@ -14,2 +14,3 @@
import cn from '@/utils/classnames'
import DOMPurify from 'dompurify'

@@ -42,2 +43,4 @@

const sanitizedDetailUrl = DOMPurify.sanitize(detailUrl)

return (
@@ -80,3 +83,3 @@
{(source === PluginSource.marketplace || source === PluginSource.github) && (
<a href={detailUrl} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover flex cursor-pointer items-center rounded-lg px-3 py-1.5'>
<a href={sanitizedDetailUrl} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover flex cursor-pointer items-center rounded-lg px-3 py-1.5'>
<span className='grow'>{t('plugin.detailPanel.operation.viewDetail')}</span>
web/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/package.json b/web/package.json
--- a/web/package.json
+++ b/web/package.json
@@ -122,3 +122,4 @@
         "zundo": "^2.1.0",
-        "zustand": "^4.5.2"
+        "zustand": "^4.5.2",
+        "dompurify": "^3.2.4"
     },
EOF
@@ -122,3 +122,4 @@
"zundo": "^2.1.0",
"zustand": "^4.5.2"
"zustand": "^4.5.2",
"dompurify": "^3.2.4"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.4 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
<a href={`${MARKETPLACE_URL_PREFIX}/plugins/${author}/${name}`} target='_blank' className='block px-3 py-1.5 rounded-lg text-text-secondary system-md-regular cursor-pointer hover:bg-state-base-hover'>{t('common.operation.viewDetails')}</a>
<div className='bg-components-panel-bg-blur border-components-panel-border w-[112px] rounded-xl border-[0.5px] p-1 shadow-lg'>
<div onClick={handleDownload} className='text-text-secondary system-md-regular hover:bg-state-base-hover cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.download')}</div>
<a href={`${MARKETPLACE_URL_PREFIX}/plugins/${author}/${name}`} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover block cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.viewDetails')}</a>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix AI 5 days ago

To fix the problem, we need to ensure that the value of MARKETPLACE_URL_PREFIX is properly sanitized before being used in the href attribute. One way to achieve this is by using a library like DOMPurify to sanitize the URL. This will ensure that any potentially malicious content is removed before the URL is used.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the relevant file.
  3. Use DOMPurify to sanitize the MARKETPLACE_URL_PREFIX before using it in the href attribute.
Suggested changeset 2
web/app/components/workflow/block-selector/market-place-plugin/action.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/app/components/workflow/block-selector/market-place-plugin/action.tsx b/web/app/components/workflow/block-selector/market-place-plugin/action.tsx
--- a/web/app/components/workflow/block-selector/market-place-plugin/action.tsx
+++ b/web/app/components/workflow/block-selector/market-place-plugin/action.tsx
@@ -16,2 +16,3 @@
 import { downloadFile } from '@/utils/format'
+import DOMPurify from 'dompurify'
 
@@ -62,2 +63,3 @@
   }, [blob])
+  const sanitizedMarketplaceUrlPrefix = DOMPurify.sanitize(MARKETPLACE_URL_PREFIX)
   return (
@@ -80,3 +82,3 @@
           <div onClick={handleDownload} className='text-text-secondary system-md-regular hover:bg-state-base-hover cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.download')}</div>
-          <a href={`${MARKETPLACE_URL_PREFIX}/plugins/${author}/${name}`} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover block cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.viewDetails')}</a>
+          <a href={`${sanitizedMarketplaceUrlPrefix}/plugins/${author}/${name}`} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover block cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.viewDetails')}</a>
         </div>
EOF
@@ -16,2 +16,3 @@
import { downloadFile } from '@/utils/format'
import DOMPurify from 'dompurify'

@@ -62,2 +63,3 @@
}, [blob])
const sanitizedMarketplaceUrlPrefix = DOMPurify.sanitize(MARKETPLACE_URL_PREFIX)
return (
@@ -80,3 +82,3 @@
<div onClick={handleDownload} className='text-text-secondary system-md-regular hover:bg-state-base-hover cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.download')}</div>
<a href={`${MARKETPLACE_URL_PREFIX}/plugins/${author}/${name}`} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover block cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.viewDetails')}</a>
<a href={`${sanitizedMarketplaceUrlPrefix}/plugins/${author}/${name}`} target='_blank' className='text-text-secondary system-md-regular hover:bg-state-base-hover block cursor-pointer rounded-lg px-3 py-1.5'>{t('common.operation.viewDetails')}</a>
</div>
web/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/web/package.json b/web/package.json
--- a/web/package.json
+++ b/web/package.json
@@ -122,3 +122,4 @@
         "zundo": "^2.1.0",
-        "zustand": "^4.5.2"
+        "zustand": "^4.5.2",
+        "dompurify": "^3.2.4"
     },
EOF
@@ -122,3 +122,4 @@
"zundo": "^2.1.0",
"zustand": "^4.5.2"
"zustand": "^4.5.2",
"dompurify": "^3.2.4"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.4 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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.