2015-05-14 14 views
6

Sto cercando di parametrizzare una query che sta attualmente lavorando ed è maturo per un attacco SQL injection:interrogazione Parametrizzazione ORM con cui nella clausola

qryAwards = ORMExecuteQuery(
    "from Award where awardID in (#form.deleteAwardList#) and Game.Season.User.userID=:uid", 
    {uid=session.userID} 
); 
if(not isNull(qryAwards) and arrayLen(qryAwards)){ 
    for(i in qryAwards){ 
     entityDelete(i); 
    } 
} 

Ho provato questo, avendo il parametro senza virgolette singole:

qryAwards = ORMExecuteQuery(
    "from Award where awardID in (:awardList) and Game.Season.User.userID=:uid", 
    {awardList=form.deleteAwardList, uid=session.userID} 
); 

Continuo a ricevere il seguente errore:

The value 117,118 cannot be converted to a number.

E questo, con il parametro racchiuso tra virgolette singole:

qryAwards = ORMExecuteQuery(
    "from Award where awardID in (':awardList') and Game.Season.User.userID=:uid", 
    {awardList=form.deleteAwardList, uid=session.userID} 
); 

me ottiene il seguente errore:

Invalid parameters specified for the query.

risposta

6

In HQL (che è quello che si usa quando si fa ORMExecuteQuery()) parametri utilizzati in una clausola IN deve essere passata come una matrice. È necessario convertire form.deleteAwardList in un array. Ci sono diversi modi per gestirlo, ma funzionerà.

qryAwards = ORMExecuteQuery(
    "from Award where awardID in (:awardList) and Game.Season.User.userID=:uid", 
    {awardList=listToArray(form.deleteAwardList), uid=session.userID} 
); 
+0

Grazie, funziona! – TekiusFanatikus

+0

Per pura curiosità, questo approccio sfugge agli apostrofi? –

+1

Dovrebbe. Ogni volta che si parametrizzano i dati come questi caratteri speciali, viene eseguito l'escape, proprio come in 'cfparam'. Inoltre, non puoi usare 'cfqueryparam' wtih' ORMExecuteQuery() '. Utilizzando i parametri come è, è come usare 'cfqueryparam' –