CVE-2023-5104: Improper Input Validation (CWE-20)
value: Improper Input Validation in GitHub repository nocodb/nocodb prior to 0.96.0.
CWE description: The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.
CVSS v3 base score: 6.5
Published: 2023-09-21T09:15Z
Repository: https://github.com/nocodb/nocodb
Language: Other
Files changed: packages/nc-gui-v2/components/dlg/TableRename.vue
Commit date: 2022-08-12 18:13:55 +0800
Commit message: feat(gui-v2): add table name length validator

Diff: diff --git a/packages/nc-gui-v2/components/dlg/TableRename.vue b/packages/nc-gui-v2/components/dlg/TableRename.vue
index 3b5866078..2b89e802a 100644
--- a/packages/nc-gui-v2/components/dlg/TableRename.vue
+++ b/packages/nc-gui-v2/components/dlg/TableRename.vue
@@ -22,12 +22,11 @@ const dialogShow = computed({
     emit('update:modelValue', v)
   },
 })
 
 const { updateTab } = useTabs()
-const { loadTables } = useProject()
-const { tables } = useProject()
+const { loadTables, tables, project, isMysql, isMssql, isPg } = useProject()
 
 const inputEl = $ref<any>()
 let loading = $ref(false)
 const useForm = Form.useForm
 const formState = reactive({
@@ -35,10 +34,29 @@ const formState = reactive({
 })
 const validators = computed(() => {
   return {
     title: [
       validateTableName,
+      {
+        validator: (rule: any, value: any) => {
+          return new Promise<void>((resolve, reject) => {
+            let tableNameLengthLimit = 255
+            if (isMysql) {
+              tableNameLengthLimit = 64
+            } else if (isPg) {
+              tableNameLengthLimit = 63
+            } else if (isMssql) {
+              tableNameLengthLimit = 128
+            }
+            const projectPrefix = project?.value?.prefix || ''
+            if ((projectPrefix + value).length > tableNameLengthLimit) {
+              return reject(new Error(`Table name exceeds ${tableNameLengthLimit} characters`))
+            }
+            resolve()
+          })
+        },
+      },
       {
         validator: (rule: any, value: any, callback: (errMsg?: string) => void) => {
           if (/^\s+|\s+$/.test(value)) {
             callback('Leading or trailing whitespace not allowed in table name')
           }

Vulnerable code: const { loadTables } = useProject()
const { tables } = useProject()
Fixed code: const { loadTables, tables, project, isMysql, isMssql, isPg } = useProject()
      {
        validator: (rule: any, value: any) => {
          return new Promise<void>((resolve, reject) => {
            let tableNameLengthLimit = 255
            if (isMysql) {
              tableNameLengthLimit = 64
            } else if (isPg) {
              tableNameLengthLimit = 63
            } else if (isMssql) {
              tableNameLengthLimit = 128
            }
            const projectPrefix = project?.value?.prefix || ''
            if ((projectPrefix + value).length > tableNameLengthLimit) {
              return reject(new Error(`Table name exceeds ${tableNameLengthLimit} characters`))
            }
            resolve()
          })
        },
      },