mirror of
https://github.com/github/codeql.git
synced 2026-05-20 14:17:11 +02:00
This pull request introduces a new CodeQL query for detecting prompt injection vulnerabilities in Python code targeting AI prompting APIs such as agents and openai. The changes includes a new experimental query, new taint flow and type models, a customizable dataflow configuration, documentation, and comprehensive test coverage.
39 lines
983 B
Python
39 lines
983 B
Python
from agents import Agent, Runner
|
|
from flask import Flask, request # $ Source
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/parameter-route")
|
|
def get_input1():
|
|
input = request.args.get("input")
|
|
|
|
agent = Agent(name="Assistant", instructions="This prompt is customized for " + input) # $Alert[py/prompt-injection]
|
|
|
|
result = Runner.run_sync(agent, "This is a user message.")
|
|
print(result.final_output)
|
|
|
|
|
|
@app.route("/parameter-route")
|
|
def get_input2():
|
|
input = request.args.get("input")
|
|
|
|
agent = Agent(name="Assistant", instructions="This prompt is not customized.")
|
|
result = Runner.run_sync(
|
|
agent=agent,
|
|
input=[
|
|
{
|
|
"role": "user",
|
|
"content": input, # $Alert[py/prompt-injection]
|
|
}
|
|
]
|
|
)
|
|
|
|
result2 = Runner.run_sync(
|
|
agent,
|
|
[
|
|
{
|
|
"role": "user",
|
|
"content": input, # $Alert[py/prompt-injection]
|
|
}
|
|
]
|
|
)
|