SKY-D267 · Security in code
LLM call or agent loop with no limits
Every call to a hosted model costs money per token and can take minutes to answer. SKY-D267 reports a model call with no cap on the length of the answer or no timeout, a model call inside a loop that never ends, and an agent executor with no limit on how many steps it may take.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- Unbounded LLM consumption
Why it matters
One user can send long requests in a loop and run up the bill, or keep the server's workers waiting on slow answers until other users time out. An agent with no step limit can call tools and the model over and over on a single request.
What Skylos flags
from flask import Flask, requestfrom openai import OpenAI app = Flask(__name__)client = OpenAI() SYSTEM_PROMPT = "Translate the user's text into French." @app.post("/translate")def translate(): reply = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": request.json["text"]}, ], ) return {"french": reply.choices[0].message.content}What Skylos leaves alone
from flask import Flask, requestfrom openai import OpenAI app = Flask(__name__)client = OpenAI(timeout=20, max_retries=2) @app.post("/search/embed")def embed_query(): texts = request.json["texts"][:16] result = client.embeddings.create(model="text-embedding-3-small", input=texts) return {"vectors": [item.embedding for item in result.data]}Why Skylos leaves it alone
This call has no max_tokens either, but it is an embeddings call: the answer is a fixed-size list of numbers, so no token cap is needed. The timeout is set once on the client, and Skylos reads limits from the client's constructor as well as from the call.
More languages
Python
Flagged
from langchain.agents import AgentExecutor, create_tool_calling_agent from app.tools import TOOLS, model, prompt agent = create_tool_calling_agent(model, TOOLS, prompt)executor = AgentExecutor(agent=agent, tools=TOOLS)Not flagged
from langchain.agents import AgentExecutor, create_tool_calling_agent from app.tools import TOOLS, model, prompt agent = create_tool_calling_agent(model, TOOLS, prompt)executor = AgentExecutor( agent=agent, tools=TOOLS, max_iterations=8, max_execution_time=60,)Why Skylos leaves it alone
The executor stops after 8 steps or 60 seconds. Either max_iterations, max_iter or max_execution_time is enough.
How Skylos decides
- Runs with
--dangeron Python files that mention an LLM library or an agent API. - Finds model calls: a call ending in
.chat.completions.create,.responses.create,.messages.create,.embeddings.create,.invoke,.invoke_model,.predictor.generateon a client built in the same file withOpenAI(),Anthropic(),ChatOpenAI()and similar, or on a name calledopenai,anthropic,llm,chainand so on; alsolitellm.completion(). - Lists what is missing. "No max token limit" when neither the call nor the client constructor sets
max_tokens,max_completion_tokens,max_output_tokensormaxOutputTokens(embedding calls are exempt). "No request timeout" when neither setstimeout,request_timeoutortimeout_seconds. A value ofNoneorFalsecounts as missing. Settings passed as**paramsare read whenparamsis a dictionary literal in the same function; an unknown**spread is trusted. - Adds "call runs inside an obvious unbounded loop" for a call inside
while True:or aforoveritertools.count(),cycle()orrepeat()without a count. - Reports
AgentExecutor(...),AgentExecutor.from_agent_and_tools(...)andinitialize_agent(...)withoutmax_iterations,max_iterormax_execution_time. - Each case is one MEDIUM finding on the line where the call starts.
How to fix it
Set a timeout on the client, cap the answer with max_tokens (or max_output_tokens for the Responses API) and cut the input to a size you are willing to pay for. Add per-user rate limits in front of the route as well; Skylos does not check for those.
from flask import Flask, requestfrom openai import OpenAI app = Flask(__name__)Removed: client = OpenAI()Added: client = OpenAI(timeout=20, max_retries=2) SYSTEM_PROMPT = "Translate the user's text into French."Added: MAX_INPUT_CHARS = 4000 @app.post("/translate")def translate():Added: text = request.json["text"][:MAX_INPUT_CHARS] reply = client.chat.completions.create( model="gpt-4o-mini",Added: max_tokens=1200, messages=[ {"role": "system", "content": SYSTEM_PROMPT},Removed: {"role": "user", "content": request.json["text"]},Added: {"role": "user", "content": text}, ], ) return {"french": reply.choices[0].message.content}When it can be wrong
- A timeout set another way is not seen:
OpenAI(http_client=httpx.Client(timeout=20))still gives "no request timeout". The OpenAI and Anthropic SDKs also have default timeouts of their own, which the rule does not count. - Missed: clients built by a factory in another module and calls through
client.with_options(...)(neither is recognised as a model call), the size of the input, rate limits per user,whileloops whose condition may never become false, LangGraph agents (create_react_agent, limited byrecursion_limit), and code in other languages.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line where the call starts.
Python reply = client.chat.completions.create( # skylos: ignore[SKY-D267] limits in factoryskylos baseline ., then--baseline, accepts reviewed calls and reports new ones.[tool.skylos] ignore = ["SKY-D267"]turns the rule off for the whole project.