Fuzz a single parameter.
(
self,
client: httpx.AsyncClient,
base_url: str,
endpoint: APIEndpoint,
param: APIParameter,
payload: any,
headers: dict,
baseline: Optional[httpx.Response],
)
| 247 | return builtin + extra |
| 248 | |
| 249 | async def _fuzz_parameter( |
| 250 | self, |
| 251 | client: httpx.AsyncClient, |
| 252 | base_url: str, |
| 253 | endpoint: APIEndpoint, |
| 254 | param: APIParameter, |
| 255 | payload: any, |
| 256 | headers: dict, |
| 257 | baseline: httpx.Response | None, |
| 258 | ) -> FuzzResult: |
| 259 | """Fuzz a single parameter.""" |
| 260 | url = urljoin(base_url, endpoint.path.replace("{", "1").replace("}", "")) |
| 261 | |
| 262 | result = FuzzResult( |
| 263 | endpoint=endpoint.path, |
| 264 | method=endpoint.method, |
| 265 | parameter=param.name, |
| 266 | payload=str(payload)[:100], # Truncate for logging |
| 267 | status_code=0, |
| 268 | response_time=0.0, |
| 269 | ) |
| 270 | |
| 271 | try: |
| 272 | # Build request based on parameter location |
| 273 | kwargs = {"headers": headers} |
| 274 | |
| 275 | if param.location == "query": |
| 276 | kwargs["params"] = {param.name: payload} |
| 277 | elif param.location == "path": |
| 278 | url = url.replace("1", str(payload)) |
| 279 | elif param.location == "header": |
| 280 | kwargs["headers"] = {**headers, param.name: str(payload)} |
| 281 | |
| 282 | response = await client.request( |
| 283 | method=endpoint.method, |
| 284 | url=url, |
| 285 | **kwargs, |
| 286 | ) |
| 287 | |
| 288 | result.status_code = response.status_code |
| 289 | result.response_time = response.elapsed.total_seconds() |
| 290 | |
| 291 | # Check for anomalies |
| 292 | finding = self._check_anomaly(endpoint, param, payload, response, baseline) |
| 293 | if finding: |
| 294 | result.anomaly = True |
| 295 | result.finding = finding |
| 296 | |
| 297 | except httpx.TimeoutException: |
| 298 | result.anomaly = True |
| 299 | result.finding = Finding( |
| 300 | title="Request Timeout on Fuzz Input", |
| 301 | description=f"{endpoint.method} {endpoint.path} timed out with payload in {param.name}", |
| 302 | severity=Severity.LOW, |
| 303 | source="apisec.fuzzer", |
| 304 | data={"parameter": param.name, "payload": str(payload)[:100]}, |
| 305 | ) |
| 306 | except Exception as e: |
no test coverage detected