Baroshem / nuxt-security

🛡 Automatically configure your app to follow OWASP security patterns and principles by using HTTP Headers and Middleware
https://nuxt-security.vercel.app/
MIT License
738 stars 56 forks source link

ERROR [nuxt] [request error] [unhandled] [500] readMultipartFormData is not defined #421

Closed moshetanzer closed 2 months ago

moshetanzer commented 2 months ago

Version

nuxt-security: Latest nuxt: Latest

Reproduction Link

Steps to reproduce

Getting the following error when submitting a form wuth nuxt-security enabled - this has only occured since updated to latest nuxt (though downgraded and still getting issue - didnt try downgrade nuxt-seucruty)

ERROR  [nuxt] [request error] [unhandled] [500] readMultipartFormData is not defined
  at Object.handler (./node_modules/.pnpm/nuxt-security@1.3.1_rollup@2.79.1/node_modules/nuxt-security/dist/runtime/server/middleware/xssValidator.mjs:26:13)  
  at ./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:31  
  at async Object.callAsync (./node_modules/.pnpm/unctx@2.3.1/node_modules/unctx/dist/index.mjs:72:16)  
  at async Server.toNodeHandle (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:7)

Client Side


async function login(e: any) {
  loggingIn.value = true;
  try {
    console.log(e);
    const formData = new FormData();

    // Append each form field to the FormData object
    Object.keys(e).forEach((key) => {
      formData.append(key, e[key]);
    });
    console.log(formData);
    await $fetch("/api/auth/login", {
      method: "POST",
      body: formData
    });
    await navigateTo("/dashboard");
  } catch (err: any) {

    loggingIn.value = false;
    error.value = err.data?.message ?? null;
    toast.add({ title: 'Error', description: error.value ?? 'An error occurred', icon: 'i-heroicons-information-circle-20-solid', color: 'rose'})
  }
}

Server side:


export default eventHandler(async (event) => {
    const formData = await readFormData(event);
    const username = formData.get("username");
    const password = formData.get("password");
moshetanzer commented 2 months ago

Thanks for libary!

Baroshem commented 2 months ago

Hey, thanks for reporting this. It was actually missing from the import statement. Should be fixed in 1.3.2 version :)

Please let me know if it works now so that I could close the ticket

moshetanzer commented 2 months ago

Solved