QWED

Type to search pages, engines and advisories.

    Looking for API details?Search the docs

    Security·Advisories·GHSA-hg68-hg59-ph4v

    POST /agents/register accepts any API key of an organisation, so a viewer can register an agent with any permissions and daily budget

    lowFixed in 13.0.0GHSA-hg68-hg59-ph4v · Published 2 December 2026

    Impact

    POST /agents/register (src/qwed_new/api/main.py:1737-1772) depends only on get_current_tenant, so any live API key of an organisation can register an agent, whatever the role of the user who owns the key. The caller chooses the agent's permissions and max_cost_per_day and gets an agent token back. AgentRegistry.register_agent (src/qwed_new/core/agent_registry.py:38-79) stores both as sent, and created_by_user_id stays empty because the route does not pass it.

    The routes that manage agents require an owner or an admin: GET /agents and the owner's view of GET /agents/{agent_id}/activity use require_admin_role(["owner", "admin"]) (src/qwed_new/api/agent_admin_routes.py:36). So a viewer whose key is refused on GET /agents can still create an agent with permissions and a daily budget their role does not give them.

    Checked on main @ 6cb53f00 (11.0.0), with a viewer's API key:

    Request Result
    GET /agents 403
    POST /agents/register with permissions: ["execute_code", "database_write"] and max_cost_per_day: 1e9 200 and an agent token. Stored with budget 1e9, both permissions and created_by_user_id None

    The agent stays inside the caller's organisation. Tool execution is simulated today, so the permissions do not run anything yet; the agent can call POST /agents/{agent_id}/verify, which spends the organisation's provider budget, and the daily budget is not enforced on the tool-call path either (#393). Once tools run for real, a self-granted execute_code or database_write matters more.

    Affected

    qwed (PyPI) through 12.0.0, the API server (qwed_new.api.main). The SDKs are not affected.

    Reproduction

    from fastapi.testclient import TestClient
    from sqlmodel import Session, SQLModel, create_engine
    
    from qwed_new.api import main
    from qwed_new.auth.security import generate_api_key
    from qwed_new.core.models import ApiKey, Organization, User
    
    engine = create_engine("sqlite:///agents.db")
    SQLModel.metadata.create_all(engine)
    session = Session(engine)
    
    
    def add(row):
        session.add(row)
        session.commit()
        session.refresh(row)
        return row
    
    
    org = add(Organization(name="acme", display_name="Acme"))
    viewer = add(User(email="viewer@acme.example.com", password_hash="x", organization_id=org.id, role="viewer"))
    raw, digest = generate_api_key()
    add(ApiKey(key_hash=digest, key_preview=raw[:8], organization_id=org.id, user_id=viewer.id))
    
    main.app.dependency_overrides[main.get_session] = lambda: session
    client = TestClient(main.app)
    headers = {"x-api-key": raw}
    print(client.get("/agents", headers=headers).status_code)  # 403
    response = client.post("/agents/register", headers=headers, json={
        "name": "x", "permissions": ["execute_code", "database_write"], "max_cost_per_day": 1e9,
    })
    print(response.status_code, bool(response.json().get("agent_token")))  # 200 True
    

    Details

    TenantContext carries the organisation and the API key, not the role of the key's user, so a route that takes only get_current_tenant cannot check a role. The agent routes added later (#527) use require_admin_role; the registration route was not moved to it.

    Patches

    Fixed in 13.0.0. Upgrade with pip install -U "qwed>=13.0.0". POST /agents/register needs an owner or an admin (an API key or a signed-in session), as the other agent routes do, and records created_by_user_id. A permission must be use_tool_<tool> for one of the six tools the tool route approves (tool_approval.SAFE_OPERATIONS), given once, and the daily budget must be above 0 and at most 10,000; otherwise the request is refused with 422. AgentRegistry.register_agent applies the same rule.

    Workarounds

    Issue API keys only to users who may create agents, and review an organisation's agents with GET /agents, suspending any that nobody registered on purpose.

    Advisory page: https://qwedai.tech/security/advisories/ghsa-hg68-hg59-ph4v

    All advisories

    Affected and fixed

    qwed

    Affected<= 12.0.0 Fixed in13.0.0
    Weakness
    CWE-862 Missing Authorization
    View on GitHub