Skip to main content

Configuring advanced setup for code scanning

You can configure advanced setup for a repository to find security vulnerabilities in your code using a highly customizable code scanning configuration.

¿Quién puede utilizar esta característica?

Propietarios de repositorios, propietarios de organizaciones, administradores de seguridad y usuarios con el rol de administrador

Code scanning está disponible para los tipos de repositorio siguientes:

  • Repositorios públicos en GitHub.com
  • Repositorios propiedad de la organización en GitHub Team, GitHub Enterprise Cloud, o GitHub Enterprise Server, con GitHub Code Security habilitados.

If you do not need a highly customizable code scanning configuration, consider using default setup for code scanning. For more information, see Acerca de los tipos de configuración para el examen de código.

Prerequisites

Your repository is eligible for advanced setup if it meets these requirements.

  • It uses CodeQL-supported languages or you plan to generate code scanning results with a third-party tool.
  • GitHub Actions está habilitado.
  • Es visible públicamente o GitHub Code Security se ha habilitado.

Configuring advanced setup for code scanning with CodeQL

You can customize your CodeQL analysis by creating and editing a workflow file. Selecting advanced setup generates a basic workflow file for you to customize using standard workflow syntax and specifying options for the CodeQL action. See Flujos de trabajo and Opciones de configuración de flujo de trabajo para el examen de código.

Al usar acciones para ejecutar code scanning se usarán minutos. Para más información, consulta facturación de GitHub Actions

Nota:

You can configure code scanning for any public repository where you have write access.

  1. En GitHub, navegue hasta la página principal del repositorio.

  2. Debajo del nombre del repositorio, haz clic en Settings. Si no puedes ver la pestaña "Configuración", selecciona el menú desplegable y, a continuación, haz clic en Configuración.

    Captura de pantalla de un encabezado de repositorio en el que se muestran las pestañas. La pestaña "Configuración" está resaltada con un contorno naranja oscuro.

  3. En la sección "Security" de la barra lateral, haz clic en Advanced Security.

  4. Scroll down to "Code Security", in the "CodeQL analysis" row select Set up , then click Advanced.

    Nota:

    If you are switching from default setup to advanced setup, in the "CodeQL analysis" row, select , then click Switch to advanced. In the pop-up window that appears, click Disable CodeQL.

    Screenshot of the "Code Security" section of "Advanced Security" settings. The "Advanced setup" button is highlighted with an orange outline.

  5. To customize how code scanning scans your code, edit the workflow.

    Generally, you can commit the Flujo de trabajo de análisis de CodeQL without making any changes to it. However, many of the third-party workflows require additional configuration, so read the comments in the workflow before committing.

    For more information, see Opciones de configuración de flujo de trabajo para el examen de código and CodeQL code scanning for compiled languages.

  6. Click Commit changes... to display the commit changes form.

    Screenshot of the form to create a new file. To the right of the file name, a green button, labeled "Commit changes...", is outlined in dark orange.

  7. In the commit message field, type a commit message.

  8. Choose whether you'd like to commit directly to the default branch, or create a new branch and start a pull request.

  9. Click Commit new file to commit the workflow file to the default branch or click Propose new file to commit the file to a new branch.

  10. If you created a new branch, click Create pull request and open a pull request to merge your change into the default branch.

In the suggested Flujo de trabajo de análisis de CodeQL, code scanning is configured to analyze your code each time you either push a change to the default branch or any protected branches, or raise a pull request against the default branch. As a result, code scanning will now commence.

The on:pull_request and on:push triggers for code scanning are each useful for different purposes. See Opciones de configuración de flujo de trabajo para el examen de código and Activar un flujo de trabajo.

For information on bulk enablement, see Establecimiento de la configuración avanzada para el examen de código con CodeQL a gran escala.

Configuring code scanning using third-party actions

GitHub includes workflow templates for third-party actions, as well as the CodeQL action. Using a workflow template is much easier than writing a workflow unaided.

Al usar acciones para ejecutar code scanning se usarán minutos. Para más información, consulta facturación de GitHub Actions

  1. En GitHub, navegue hasta la página principal del repositorio.

  2. En el nombre del repositorio, haz clic en Actions.

    Captura de pantalla de las pestañas del repositorio "github/docs". La pestaña "Proyectos" aparece resaltada con un contorno naranja.

  3. If the repository has already at least one workflow configured and running, click New workflow to display workflow templates. If there are currently no workflows configured for the repository, go to the next step.

    Screenshot of the Actions tab for a repository. The "New workflow" button is outlined in dark orange.

  4. In the "Choose a workflow" or "Get started with GitHub Actions" view, scroll down to the "Security" category and click Configure under the workflow you want to configure. You may need to click View all to find the security workflow you want to configure.

    Screenshot of the Security category of workflow templates. The Configure button and "View all" link are highlighted with an orange outline.

  5. Follow any instructions in the workflow to customize it to your needs. For more general assistance about workflows, click Documentation on the right pane of the workflow page.

    Screenshot showing a workflow template file open for editing. The "Documentation" button is highlighted with an orange outline.

  6. When you have finished defining your configuration, add the new workflow to your default branch.

    For more information, see Uso de plantillas de flujo de trabajo and Opciones de configuración de flujo de trabajo para el examen de código.

Next steps

After your workflow runs successfully at least once, you are ready to start examining and resolving code scanning alerts. For more information on code scanning alerts, see Acerca de las alertas de análisis de código and Evaluación de alertas de análisis de código para el repositorio.

Learn how code scanning runs behave as checks on pull requests, see Clasificar las alertas del escaneo de código en las solicitudes de cambios.

You can find detailed information about your code scanning configuration, including timestamps for each scan and the percentage of files scanned, on the tool status page. For more information, see Use the tool status page for code scanning.

Further reading