- Blogs
- Adobe ColdFusion
- Simple Secure Code ChatGPT Demo
If you haven’t heard, there’s this cool new thing the kids are doing called “AI”. I’m not sure what that stands for, but it is very popular.
One of these AIs is a Large Language Model called ChatGPT, which comes in a variety of flavors (and costs!). Today I wanted to show you how easy it is to build a simple little app that will send the code in one your files in to ChatGPT and have it check for security concerns.
We’re going to be using Adobe ColdFusion’s powerful file capability here, in particular the fileRead() function. Let’s dive into the code (please assume this code is inside a <cfscript> block).
var filePath = "C:\ProjectFortuna\cfusion\wwwroot\cffiledemo\demofile.cfm";
<cfquery name="demoquery" datasource="demosource"> SELECT * FROM tbl_main WHERE id = #URL.id# </cfquery> <cfdump var="#demoquery#" />
var fileContents = "Is the following code secure? If not, explain why." & EncodeForHTML(fileRead(filePath));
httpService.setUrl("https://api.openai.com/v1/chat/completions");
httpService.setMethod("post");
httpService.addParam(type="header", name="Content-Type", value="application/json");
httpService.addParam(type="header", name="Authorization", value="#APPLICATION.openaikey#");
httpService.addParam(type="body", value='{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "#fileContents#"}]
}');
apiResponse = httpService.send().getPrefix); writeDump(apiResponse.filecontent);
{"id":"chatcmpl-7Oumow5OU9DUIBT0zvhj69pyGDEGE","object":"chat.completion","created":1686172514,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":138,"completion_tokens":63,"total_tokens":201},"choices":[{"message":{"role":"assistant","content":"The code is not secure because it is vulnerable to SQL injection attacks. The query includes directly user-inputted values from the URL without any sanitization or validation, which can allow malicious users to manipulate the query to execute unintended commands. A safer approach would be to use prepared statements or input validation to mitigate this risk."},"finish_reason":"stop","index":0}]}
If you haven’t heard, there’s this cool new thing the kids are doing called “AI”. I’m not sure what that stands for, but it is very popular.
One of these AIs is a Large Language Model called ChatGPT, which comes in a variety of flavors (and costs!). Today I wanted to show you how easy it is to build a simple little app that will send the code in one your files in to ChatGPT and have it check for security concerns.
We’re going to be using Adobe ColdFusion’s powerful file capability here, in particular the fileRead() function. Let’s dive into the code (please assume this code is inside a <cfscript> block).
var filePath = "C:\ProjectFortuna\cfusion\wwwroot\cffiledemo\demofile.cfm";
<cfquery name="demoquery" datasource="demosource"> SELECT * FROM tbl_main WHERE id = #URL.id# </cfquery> <cfdump var="#demoquery#" />
var fileContents = "Is the following code secure? If not, explain why." & EncodeForHTML(fileRead(filePath));
httpService.setUrl("https://api.openai.com/v1/chat/completions");
httpService.setMethod("post");
httpService.addParam(type="header", name="Content-Type", value="application/json");
httpService.addParam(type="header", name="Authorization", value="#APPLICATION.openaikey#");
httpService.addParam(type="body", value='{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "#fileContents#"}]
}');
apiResponse = httpService.send().getPrefix); writeDump(apiResponse.filecontent);
{"id":"chatcmpl-7Oumow5OU9DUIBT0zvhj69pyGDEGE","object":"chat.completion","created":1686172514,"model":"gpt-3.5-turbo-0301","usage":{"prompt_tokens":138,"completion_tokens":63,"total_tokens":201},"choices":[{"message":{"role":"assistant","content":"The code is not secure because it is vulnerable to SQL injection attacks. The query includes directly user-inputted values from the URL without any sanitization or validation, which can allow malicious users to manipulate the query to execute unintended commands. A safer approach would be to use prepared statements or input validation to mitigate this risk."},"finish_reason":"stop","index":0}]}





