Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    XSS & SQL Injection?

    Cloud Backend (Cloud DB, API Builder)
    4
    4
    301
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Thomas D last edited by

      Do you filter parameter inputs from this or do we need to do this in code?

      1 Reply Last reply Reply Quote 0
      • Daniel Mulroy
        Daniel Mulroy last edited by

        FWIW, from what i've seen, there is no protection against SQL injection in the input you receive, it's raw from the sender.

        Not sure about XSS/CORS settings.

        1 Reply Last reply Reply Quote 0
        • Joseph Benguira
          Joseph Benguira last edited by Joseph Benguira

          We do protect for SQL Injection the Visual SQL endpoints, but for real languages (Node.js, C#, Java, Python, ...)
          since it's your own code you have to do it by yourself of use a library ...

          In node.js here is how you can protect a parameter from SQL Injection:

          You need this function

          function Clean(txt){
               if ( txt == null) {  return "";  }
               else{
                    return txt.replace(/\'/g, "''");
               }
          }
          

          Then you can call it like this:

          var myParam = event.POST.myParam;
          var SQL = "SELECT * FROM MyTable WHERE myColumn = '" + Clean(MyParam) + "'";
          

          Here is another equivalent syntax with brackets & backticks:

          var myParam = event.POST.myParam;
          var SQL = `SELECT * FROM MyTable WHERE myColumn = '${Clean(MyParam)}'`;
          
          1 Reply Last reply Reply Quote 1
          • Wassim
            Wassim last edited by

            I'd like to share another method which is less error prone :

            function escapeSQL(strings, ...vars) {
                return vars.reduce((str, v, i) => {
                    if (typeof(v) == 'string') {
                        return str + v.replace(/'/g, "''") + strings[i+1];
                    } else {
                        return str + v + strings[i+1];
                    }
                }, strings[0]);
            }
            var myParam = event.POST.myParam;
            var myParam2 = event.POST.myParam2;
            var query = escapeSQL`SELECT * FROM MyTable WHERE myColumn='${myParam }' AND mySecondColumn='${myParam2 }'`
            

            This way your query won't be extra long as you don't have to call a function for each parameter

            1 Reply Last reply Reply Quote 1
            • First post
              Last post