prevent sql injection attack in dynamic query grails -


मेरे पास क्वेरी है:

  def selectQuery = "select ins" def fromQuery = " InstituteStudent ins "def whereQuery =" जहां ins.institution =: inst "def compareQuery = [inst: inst]   

और अन्य क्वेरी के रूप में:

  यदि (params.p.Address! = "") {WhereQuery + = "और ins.address = '" + + पता + "' 'डीईफ़ चेक = इंस्टीट्यूशनट्यूडेंट। एक्सएक्यूट (" इन्स्टिट्यूशन इंस्टीट्यूशन्स से चयन करेंइंटरसइन्स्टेसशन =: इंस्ट एंड आईएस .address = '"+ पता +"' ", [inst: inst])}   

अग्रिम खोज क्वेरी का परिणाम

  def allQuery = selectQuery + FromQuery + whereQuery def finalQuery = InstitutionStudent.executeQuery (allQuery.toString (), तुलना करें)   

लेकिन इंजेक्शन हमले की संभावना है ताकि इसे रोकने के लिए इस क्वेरी से पैरामीटरेटेड क्वेरी को कैसे पारित किया जाए?

आप सामान्य नामित पैरामीटर का उपयोग कर सकते हैं:

  यदि (पैरामीटर PAddress! = "") {WhereQ Uery + = "और ins.address =: पता" compareQuery.address = address def चेक = इंस्टीट्यूशन छात्र। ExecuteQuery ("इंस्टीट्यूशनल इंस्टीट्यूशन इंस्टीट्यूट्स से इन्फोस इनस्टेक्शन =: inst और ins.address =: address", [inst: inst , पता: पता])}    

Comments

Popular posts from this blog

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -

sql - PostgreSQL automatically update row at specific date -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -