java - Checkmarx highlight code as sqlinjection vulnerability -
checkmarx indicates following code snippet sql injection vulnerability.
in checkmarx report descibe below code snippet shown below
"gets user input readline element. element’s value flows through code without being sanitized or validated may enable sql injection attack"
for brevity havent included full text.
inputstreamreader isr = null; bufferedreader br = null; try{ classpathresource defaultreports = new classpathresource(dbvendor + "/sql_inserts.sql"); isr = new inputstreamreader(defaultreports.getinputstream()); br = new bufferedreader(isr); c = session.connection(); string sqlline = null; while((sqlline = br.readline()) != null) { sqlline = sqlline.trim(); statement st = null; try{ st = c.createstatement(); st.execute(sqlline); }catch(sqlexception e){ }catch(exception e){ }finally{ if (st != null) st.close(); } } } //sql_inserts.sql file contain set of insert statements
i want convert above code checkmarx friendly way.after checkmark should not highlighted code snippet high sql injection vulnerability.
a sql injection attack consists of insertion or "injection" of sql query via input data client application.
source: sql injection - owasp
in code, shown checkmarx tool, sql query sqlline executed, unchecked. can see comes stream of sort, question source of these queries.
if stream under complete control, means know contains, can consider not-exploitable. examples of such cases can using hard-coded queries or choosing (or comparing to) defined "whitelist" - known good/allowed list of queries. important: if query strings controlled 100% trusted sources can considered not exploitable
if stream or queries can somehow controlled/changed/affected user, should consider queries untrusted , unsafe. in case, steps prevent sql injection must taken. way build queries not clear code snippet specific recommendation cannot suggested here. should go on prevention methods in owasp sql injection prevention cheat sheet , choose right 1 you.
good luck!
Comments
Post a Comment