Examen del código
La API del code scanning te permite recuperar y actualizar las alertas del code scanning desde un repositorio.
Acerca de la API de examen del código
La API del code scanning te permite recuperar y actualizar las alertas del code scanning desde un repositorio. Puedes utilizar las terminales para crear reportes automatizados para las alertas del code scanning en una organización o cargar resutlados de análisis que se hayan generado utilizando con herramientas fuera de línea del code scanning. Para más información, vea "Búsqueda de vulnerabilidades de seguridad y errores en el código".
Tipos de medios personalizados para el code scanning
Hay un tipo de medios personalizado compatible para la API de REST del code scanning.
application/sarif+json
Puede usar esto con solicitudes GET enviadas al punto de conexión /analyses/{analysis_id}. Para más información sobre esta operación, vea "Obtención de un análisis de code scanning para un repositorio". Cuando se usa este tipo de medio con esta operación, la respuesta incluye un subconjunto de los datos reales que se cargaron para el análisis especificado, en lugar del resumen del análisis que se devuelve cuando se usa el tipo de medio predeterminado. La respuesta también incluye datos adicionales, como las propiedades github/alertNumber y github/alertUrl. El formato de los datos es SARIF, versión 2.1.0.
Para más información, vea "Tipos de soporte físico".
List code scanning alerts for an enterprise
Lists code scanning alerts for the default branch for all eligible repositories in an enterprise. Eligible repositories are repositories that are owned by organizations that you own or for which you are a security manager. For more information, see "Managing security managers in your organization."
To use this endpoint, you must be a member of the enterprise,
and you must use an access token with the repo scope or security_events scope.
Parameters
| Headers |
|---|
| Name, Type, Description |
acceptstringSetting to |
| Path parameters |
| Name, Type, Description |
enterprisestringRequiredThe slug version of the enterprise name. You can also substitute this value with the enterprise id. |
| Query parameters |
| Name, Type, Description |
tool_namestringThe name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either |
tool_guidstringnullThe GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either |
beforestringA cursor, as given in the Link header. If specified, the query only searches for results before this cursor. |
afterstringA cursor, as given in the Link header. If specified, the query only searches for results after this cursor. |
pageintegerPage number of the results to fetch. Default: |
per_pageintegerThe number of results per page (max 100). Default: |
directionstringThe direction to sort the results by. Default: Can be one of: |
statestringIf specified, only code scanning alerts with this state will be returned. Can be one of: |
sortstringThe property by which to sort the results. Default: Can be one of: |
HTTP response status codes
| Status code | Description |
|---|---|
200 | OK |
404 | Resource not found |
503 | Service unavailable |
Code samples
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/enterprises/ENTERPRISE/code-scanning/alertsResponse
Status: 200[
{
"number": 4,
"created_at": "2020-02-13T12:29:18Z",
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/4",
"html_url": "https://github.com/octocat/hello-world/code-scanning/4",
"state": "open",
"dismissed_by": null,
"dismissed_at": null,
"dismissed_reason": null,
"dismissed_comment": null,
"rule": {
"id": "js/zipslip",
"severity": "error",
"tags": [
"security",
"external/cwe/cwe-022"
],
"description": "Arbitrary file write during zip extraction",
"name": "js/zipslip"
},
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"most_recent_instance": {
"ref": "refs/heads/main",
"analysis_key": ".github/