Skip to content

Use latest builds for security findings finder

What does this MR do?

This MR fixes the Security::FindingsFinder to return only the findings of the latest builds(aka not retried).

Database review

This MR changes an existing query to filter the results with a join table;

Old query and its plan
SELECT
    "security_findings"."id" AS t0_r0,
    "security_findings"."scan_id" AS t0_r1,
    "security_findings"."scanner_id" AS t0_r2,
    "security_findings"."severity" AS t0_r3,
    "security_findings"."confidence" AS t0_r4,
    "security_findings"."project_fingerprint" AS t0_r5,
    "security_findings"."deduplicated" AS t0_r6,
    "security_findings"."position" AS t0_r7,
    "security_findings"."uuid" AS t0_r8,
    "security_findings"."overridden_uuid" AS t0_r9,
    "builds_security_findings"."id" AS t1_r0,
    "builds_security_findings"."status" AS t1_r1,
    "builds_security_findings"."finished_at" AS t1_r2,
    "builds_security_findings"."trace" AS t1_r3,
    "builds_security_findings"."created_at" AS t1_r4,
    "builds_security_findings"."updated_at" AS t1_r5,
    "builds_security_findings"."started_at" AS t1_r6,
    "builds_security_findings"."runner_id" AS t1_r7,
    "builds_security_findings"."coverage" AS t1_r8,
    "builds_security_findings"."commit_id" AS t1_r9,
    "builds_security_findings"."name" AS t1_r10,
    "builds_security_findings"."options" AS t1_r11,
    "builds_security_findings"."allow_failure" AS t1_r12,
    "builds_security_findings"."stage" AS t1_r13,
    "builds_security_findings"."trigger_request_id" AS t1_r14,
    "builds_security_findings"."stage_idx" AS t1_r15,
    "builds_security_findings"."tag" AS t1_r16,
    "builds_security_findings"."ref" AS t1_r17,
    "builds_security_findings"."user_id" AS t1_r18,
    "builds_security_findings"."type" AS t1_r19,
    "builds_security_findings"."target_url" AS t1_r20,
    "builds_security_findings"."description" AS t1_r21,
    "builds_security_findings"."project_id" AS t1_r22,
    "builds_security_findings"."erased_by_id" AS t1_r23,
    "builds_security_findings"."erased_at" AS t1_r24,
    "builds_security_findings"."artifacts_expire_at" AS t1_r25,
    "builds_security_findings"."environment" AS t1_r26,
    "builds_security_findings"."when" AS t1_r27,
    "builds_security_findings"."yaml_variables" AS t1_r28,
    "builds_security_findings"."queued_at" AS t1_r29,
    "builds_security_findings"."token" AS t1_r30,
    "builds_security_findings"."lock_version" AS t1_r31,
    "builds_security_findings"."coverage_regex" AS t1_r32,
    "builds_security_findings"."auto_canceled_by_id" AS t1_r33,
    "builds_security_findings"."retried" AS t1_r34,
    "builds_security_findings"."stage_id" AS t1_r35,
    "builds_security_findings"."protected" AS t1_r36,
    "builds_security_findings"."failure_reason" AS t1_r37,
    "builds_security_findings"."scheduled_at" AS t1_r38,
    "builds_security_findings"."token_encrypted" AS t1_r39,
    "builds_security_findings"."upstream_pipeline_id" AS t1_r40,
    "builds_security_findings"."resource_group_id" AS t1_r41,
    "builds_security_findings"."waiting_for_resource_at" AS t1_r42,
    "builds_security_findings"."processed" AS t1_r43,
    "builds_security_findings"."scheduling_type" AS t1_r44,
    "ci_job_artifacts"."id_convert_to_bigint" AS t2_r0,
    "ci_job_artifacts"."project_id" AS t2_r1,
    "ci_job_artifacts"."job_id_convert_to_bigint" AS t2_r2,
    "ci_job_artifacts"."file_type" AS t2_r3,
    "ci_job_artifacts"."size" AS t2_r4,
    "ci_job_artifacts"."created_at" AS t2_r5,
    "ci_job_artifacts"."updated_at" AS t2_r6,
    "ci_job_artifacts"."expire_at" AS t2_r7,
    "ci_job_artifacts"."file" AS t2_r8,
    "ci_job_artifacts"."file_store" AS t2_r9,
    "ci_job_artifacts"."file_sha256" AS t2_r10,
    "ci_job_artifacts"."file_format" AS t2_r11,
    "ci_job_artifacts"."file_location" AS t2_r12,
    "ci_job_artifacts"."id" AS t2_r13,
    "ci_job_artifacts"."job_id" AS t2_r14,
    "ci_pipelines"."id" AS t3_r0,
    "ci_pipelines"."ref" AS t3_r1,
    "ci_pipelines"."sha" AS t3_r2,
    "ci_pipelines"."before_sha" AS t3_r3,
    "ci_pipelines"."created_at" AS t3_r4,
    "ci_pipelines"."updated_at" AS t3_r5,
    "ci_pipelines"."tag" AS t3_r6,
    "ci_pipelines"."yaml_errors" AS t3_r7,
    "ci_pipelines"."committed_at" AS t3_r8,
    "ci_pipelines"."project_id" AS t3_r9,
    "ci_pipelines"."status" AS t3_r10,
    "ci_pipelines"."started_at" AS t3_r11,
    "ci_pipelines"."finished_at" AS t3_r12,
    "ci_pipelines"."duration" AS t3_r13,
    "ci_pipelines"."user_id" AS t3_r14,
    "ci_pipelines"."lock_version" AS t3_r15,
    "ci_pipelines"."auto_canceled_by_id" AS t3_r16,
    "ci_pipelines"."pipeline_schedule_id" AS t3_r17,
    "ci_pipelines"."source" AS t3_r18,
    "ci_pipelines"."config_source" AS t3_r19,
    "ci_pipelines"."protected" AS t3_r20,
    "ci_pipelines"."failure_reason" AS t3_r21,
    "ci_pipelines"."iid" AS t3_r22,
    "ci_pipelines"."merge_request_id" AS t3_r23,
    "ci_pipelines"."source_sha" AS t3_r24,
    "ci_pipelines"."target_sha" AS t3_r25,
    "ci_pipelines"."external_pull_request_id" AS t3_r26,
    "ci_pipelines"."ci_ref_id" AS t3_r27,
    "ci_pipelines"."locked" AS t3_r28,
    "scans_security_findings"."id" AS t4_r0,
    "scans_security_findings"."created_at" AS t4_r1,
    "scans_security_findings"."updated_at" AS t4_r2,
    "scans_security_findings"."build_id" AS t4_r3,
    "scans_security_findings"."scan_type" AS t4_r4,
    "scans_security_findings"."info" AS t4_r5,
    "scans_security_findings"."project_id" AS t4_r6,
    "scans_security_findings"."pipeline_id" AS t4_r7,
    "vulnerability_scanners"."id" AS t5_r0,
    "vulnerability_scanners"."created_at" AS t5_r1,
    "vulnerability_scanners"."updated_at" AS t5_r2,
    "vulnerability_scanners"."project_id" AS t5_r3,
    "vulnerability_scanners"."external_id" AS t5_r4,
    "vulnerability_scanners"."name" AS t5_r5,
    "vulnerability_scanners"."vendor" AS t5_r6
FROM
    "security_findings"
    INNER JOIN "security_scans" ON "security_findings"."scan_id" = "security_scans"."id"
    INNER JOIN "ci_builds" ON "security_scans"."build_id" = "ci_builds"."id"
    INNER JOIN "security_scans" "scans_security_findings" ON "scans_security_findings"."id" = "security_findings"."scan_id"
    LEFT OUTER JOIN "security_scans" "scans_security_findings_join" ON "scans_security_findings_join"."id" = "security_findings"."scan_id"
    LEFT OUTER JOIN "ci_builds" "builds_security_findings" ON "builds_security_findings"."id" = "scans_security_findings_join"."build_id"
        AND "builds_security_findings"."type" = 'Ci::Build'
    LEFT OUTER JOIN "ci_job_artifacts" ON "ci_job_artifacts"."job_id" = "builds_security_findings"."id"
    LEFT OUTER JOIN "ci_pipelines" ON "ci_pipelines"."id" = "builds_security_findings"."commit_id"
    LEFT OUTER JOIN "vulnerability_scanners" ON "vulnerability_scanners"."id" = "security_findings"."scanner_id"
WHERE
    "ci_builds"."type" = 'Ci::Build'
    AND "ci_builds"."commit_id" = 94
    AND "security_findings"."deduplicated" = TRUE
    AND "security_scans"."scan_type" = 2
    AND (NOT EXISTS (
            SELECT
                1
            FROM
                "security_scans"
                INNER JOIN "ci_builds" ON "ci_builds"."id" = "security_scans"."build_id"
                    AND "ci_builds"."type" = 'Ci::Build'
                INNER JOIN "projects" ON "projects"."id" = "ci_builds"."project_id"
                INNER JOIN "vulnerability_feedback" ON "vulnerability_feedback"."project_id" = "projects"."id"
            WHERE (vulnerability_feedback.category = (security_scans.scan_type - 1))
            AND "vulnerability_feedback"."feedback_type" = 0
            AND (security_scans.id = security_findings.scan_id)
            AND (vulnerability_feedback.project_fingerprint = security_findings.project_fingerprint)))
AND "security_findings"."id" IN (239, 248, 241, 242, 249, 250, 251)
ORDER BY
    "security_findings"."severity" DESC,
    "security_findings"."confidence" DESC,
    "security_findings"."id" ASC

https://explain.depesz.com/s/gpJM

Sort  (cost=94.06..94.06 rows=1 width=1957) (actual time=0.117..0.120 rows=0 loops=1)
   Sort Key: security_findings.severity DESC, security_findings.confidence DESC, security_findings.id
   Sort Method: quicksort  Memory: 25kB
   Buffers: shared hit=37
   I/O Timings: read=0.000 write=0.000
   ->  Nested Loop Left Join  (cost=6.35..94.05 rows=1 width=1957) (actual time=0.045..0.047 rows=0 loops=1)
         Buffers: shared hit=31
         I/O Timings: read=0.000 write=0.000
         ->  Nested Loop Anti Join  (cost=6.05..90.74 rows=1 width=1904) (actual time=0.044..0.046 rows=0 loops=1)
               Buffers: shared hit=31
               I/O Timings: read=0.000 write=0.000
               ->  Nested Loop Left Join  (cost=4.18..79.76 rows=1 width=1904) (actual time=0.043..0.045 rows=0 loops=1)
                     Buffers: shared hit=31
                     I/O Timings: read=0.000 write=0.000
                     ->  Nested Loop Left Join  (cost=3.61..76.36 rows=1 width=1581) (actual time=0.043..0.045 rows=0 loops=1)
                           Buffers: shared hit=31
                           I/O Timings: read=0.000 write=0.000
                           ->  Nested Loop Left Join  (cost=3.03..57.65 rows=1 width=1435) (actual time=0.043..0.044 rows=0 loops=1)
                                 Buffers: shared hit=31
                                 I/O Timings: read=0.000 write=0.000
                                 ->  Nested Loop Left Join  (cost=2.45..54.18 rows=1 width=169) (actual time=0.043..0.044 rows=0 loops=1)
                                       Buffers: shared hit=31
                                       I/O Timings: read=0.000 write=0.000
                                       ->  Nested Loop  (cost=2.02..50.73 rows=1 width=161) (actual time=0.043..0.044 rows=0 loops=1)
                                             Buffers: shared hit=31
                                             I/O Timings: read=0.000 write=0.000
                                             ->  Nested Loop  (cost=1.58..47.46 rows=1 width=114) (actual time=0.043..0.043 rows=0 loops=1)
                                                   Buffers: shared hit=31
                                                   I/O Timings: read=0.000 write=0.000
                                                   ->  Nested Loop  (cost=1.01..40.45 rows=2 width=122) (actual time=0.042..0.043 rows=0 loops=1)
                                                         Buffers: shared hit=31
                                                         I/O Timings: read=0.000 write=0.000
                                                         ->  Index Scan using security_findings_pkey on public.security_findings  (cost=0.57..19.72 rows=6 width=106) (actual time=0.042..0.042 rows=0 loops=1)
                                                               Index Cond: (security_findings.id = ANY ('{239,248,241,242,249,250,251}'::bigint[]))
                                                               Filter: security_findings.deduplicated
                                                               Rows Removed by Filter: 0
                                                               Buffers: shared hit=31
                                                               I/O Timings: read=0.000 write=0.000
                                                         ->  Index Scan using security_scans_pkey on public.security_scans  (cost=0.43..3.46 rows=1 width=16) (actual time=0.000..0.000 rows=0 loops=0)
                                                               Index Cond: (security_scans.id = security_findings.scan_id)
                                                               Filter: (security_scans.scan_type = 2)
                                                               Rows Removed by Filter: 0
                                                               I/O Timings: read=0.000 write=0.000
                                                   ->  Index Scan using ci_builds_pkey on public.ci_builds  (cost=0.58..3.50 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0)
                                                         Index Cond: (ci_builds.id = security_scans.build_id)
                                                         Filter: (((ci_builds.type)::text = 'Ci::Build'::text) AND (ci_builds.commit_id = 94))
                                                         Rows Removed by Filter: 0
                                                         I/O Timings: read=0.000 write=0.000
                                             ->  Index Scan using security_scans_pkey on public.security_scans scans_security_findings  (cost=0.43..3.26 rows=1 width=55) (actual time=0.000..0.000 rows=0 loops=0)
                                                   Index Cond: (scans_security_findings.id = security_scans.id)
                                                   I/O Timings: read=0.000 write=0.000
                                       ->  Index Scan using security_scans_pkey on public.security_scans scans_security_findings_join  (cost=0.43..3.45 rows=1 width=16) (actual time=0.000..0.000 rows=0 loops=0)
                                             Index Cond: (scans_security_findings_join.id = security_findings.scan_id)
                                             I/O Timings: read=0.000 write=0.000
                                 ->  Index Scan using ci_builds_pkey on public.ci_builds builds_security_findings  (cost=0.58..3.47 rows=1 width=1274) (actual time=0.000..0.000 rows=0 loops=0)
                                       Index Cond: (builds_security_findings.id = scans_security_findings_join.build_id)
                                       Filter: ((builds_security_findings.type)::text = 'Ci::Build'::text)
                                       Rows Removed by Filter: 0
                                       I/O Timings: read=0.000 write=0.000
                           ->  Index Scan using index_ci_job_artifacts_on_job_id_and_file_type on public.ci_job_artifacts  (cost=0.58..18.56 rows=15 width=146) (actual time=0.000..0.000 rows=0 loops=0)
                                 Index Cond: (ci_job_artifacts.job_id = builds_security_findings.id)
                                 I/O Timings: read=0.000 write=0.000
                     ->  Index Scan using ci_pipelines_pkey on public.ci_pipelines  (cost=0.57..3.39 rows=1 width=323) (actual time=0.000..0.000 rows=0 loops=0)
                           Index Cond: (ci_pipelines.id = builds_security_findings.commit_id)
                           I/O Timings: read=0.000 write=0.000
               ->  Nested Loop  (cost=1.87..10.97 rows=1 width=48) (actual time=0.000..0.000 rows=0 loops=0)
                     I/O Timings: read=0.000 write=0.000
                     ->  Nested Loop  (cost=1.45..8.85 rows=1 width=18) (actual time=0.000..0.000 rows=0 loops=0)
                           I/O Timings: read=0.000 write=0.000
                           ->  Nested Loop  (cost=1.01..6.92 rows=1 width=14) (actual time=0.000..0.000 rows=0 loops=0)
                                 I/O Timings: read=0.000 write=0.000
                                 ->  Index Scan using security_scans_pkey on public.security_scans security_scans_1  (cost=0.43..3.45 rows=1 width=18) (actual time=0.000..0.000 rows=0 loops=0)
                                       Index Cond: (security_scans_1.id = security_findings.scan_id)
                                       I/O Timings: read=0.000 write=0.000
                                 ->  Index Scan using ci_builds_pkey on public.ci_builds ci_builds_1  (cost=0.58..3.47 rows=1 width=8) (actual time=0.000..0.000 rows=0 loops=0)
                                       Index Cond: (ci_builds_1.id = security_scans_1.build_id)
                                       Filter: ((ci_builds_1.type)::text = 'Ci::Build'::text)
                                       Rows Removed by Filter: 0
                                       I/O Timings: read=0.000 write=0.000
                           ->  Index Only Scan using projects_pkey on public.projects  (cost=0.44..1.93 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0)
                                 Index Cond: (projects.id = ci_builds_1.project_id)
                                 Heap Fetches: 0
                                 I/O Timings: read=0.000 write=0.000
                     ->  Index Only Scan using vulnerability_feedback_unique_idx on public.vulnerability_feedback  (cost=0.42..2.04 rows=6 width=46) (actual time=0.000..0.000 rows=0 loops=0)
                           Index Cond: ((vulnerability_feedback.project_id = projects.id) AND (vulnerability_feedback.category = (security_scans_1.scan_type - 1)) AND (vulnerability_feedback.feedback_type = 0))
                           Heap Fetches: 0
                           I/O Timings: read=0.000 write=0.000
         ->  Index Scan using vulnerability_scanners_pkey on public.vulnerability_scanners  (cost=0.29..3.31 rows=1 width=53) (actual time=0.000..0.000 rows=0 loops=0)
               Index Cond: (vulnerability_scanners.id = security_findings.scanner_id)
               I/O Timings: read=0.000 write=0.000
New query and its plan
SELECT
    "security_findings"."id" AS t0_r0,
    "security_findings"."scan_id" AS t0_r1,
    "security_findings"."scanner_id" AS t0_r2,
    "security_findings"."severity" AS t0_r3,
    "security_findings"."confidence" AS t0_r4,
    "security_findings"."project_fingerprint" AS t0_r5,
    "security_findings"."deduplicated" AS t0_r6,
    "security_findings"."position" AS t0_r7,
    "security_findings"."uuid" AS t0_r8,
    "security_findings"."overridden_uuid" AS t0_r9,
    "builds_security_findings"."id" AS t1_r0,
    "builds_security_findings"."status" AS t1_r1,
    "builds_security_findings"."finished_at" AS t1_r2,
    "builds_security_findings"."trace" AS t1_r3,
    "builds_security_findings"."created_at" AS t1_r4,
    "builds_security_findings"."updated_at" AS t1_r5,
    "builds_security_findings"."started_at" AS t1_r6,
    "builds_security_findings"."runner_id" AS t1_r7,
    "builds_security_findings"."coverage" AS t1_r8,
    "builds_security_findings"."commit_id" AS t1_r9,
    "builds_security_findings"."name" AS t1_r10,
    "builds_security_findings"."options" AS t1_r11,
    "builds_security_findings"."allow_failure" AS t1_r12,
    "builds_security_findings"."stage" AS t1_r13,
    "builds_security_findings"."trigger_request_id" AS t1_r14,
    "builds_security_findings"."stage_idx" AS t1_r15,
    "builds_security_findings"."tag" AS t1_r16,
    "builds_security_findings"."ref" AS t1_r17,
    "builds_security_findings"."user_id" AS t1_r18,
    "builds_security_findings"."type" AS t1_r19,
    "builds_security_findings"."target_url" AS t1_r20,
    "builds_security_findings"."description" AS t1_r21,
    "builds_security_findings"."project_id" AS t1_r22,
    "builds_security_findings"."erased_by_id" AS t1_r23,
    "builds_security_findings"."erased_at" AS t1_r24,
    "builds_security_findings"."artifacts_expire_at" AS t1_r25,
    "builds_security_findings"."environment" AS t1_r26,
    "builds_security_findings"."when" AS t1_r27,
    "builds_security_findings"."yaml_variables" AS t1_r28,
    "builds_security_findings"."queued_at" AS t1_r29,
    "builds_security_findings"."token" AS t1_r30,
    "builds_security_findings"."lock_version" AS t1_r31,
    "builds_security_findings"."coverage_regex" AS t1_r32,
    "builds_security_findings"."auto_canceled_by_id" AS t1_r33,
    "builds_security_findings"."retried" AS t1_r34,
    "builds_security_findings"."stage_id" AS t1_r35,
    "builds_security_findings"."protected" AS t1_r36,
    "builds_security_findings"."failure_reason" AS t1_r37,
    "builds_security_findings"."scheduled_at" AS t1_r38,
    "builds_security_findings"."token_encrypted" AS t1_r39,
    "builds_security_findings"."upstream_pipeline_id" AS t1_r40,
    "builds_security_findings"."resource_group_id" AS t1_r41,
    "builds_security_findings"."waiting_for_resource_at" AS t1_r42,
    "builds_security_findings"."processed" AS t1_r43,
    "builds_security_findings"."scheduling_type" AS t1_r44,
    "ci_job_artifacts"."id_convert_to_bigint" AS t2_r0,
    "ci_job_artifacts"."project_id" AS t2_r1,
    "ci_job_artifacts"."job_id_convert_to_bigint" AS t2_r2,
    "ci_job_artifacts"."file_type" AS t2_r3,
    "ci_job_artifacts"."size" AS t2_r4,
    "ci_job_artifacts"."created_at" AS t2_r5,
    "ci_job_artifacts"."updated_at" AS t2_r6,
    "ci_job_artifacts"."expire_at" AS t2_r7,
    "ci_job_artifacts"."file" AS t2_r8,
    "ci_job_artifacts"."file_store" AS t2_r9,
    "ci_job_artifacts"."file_sha256" AS t2_r10,
    "ci_job_artifacts"."file_format" AS t2_r11,
    "ci_job_artifacts"."file_location" AS t2_r12,
    "ci_job_artifacts"."id" AS t2_r13,
    "ci_job_artifacts"."job_id" AS t2_r14,
    "ci_pipelines"."id" AS t3_r0,
    "ci_pipelines"."ref" AS t3_r1,
    "ci_pipelines"."sha" AS t3_r2,
    "ci_pipelines"."before_sha" AS t3_r3,
    "ci_pipelines"."created_at" AS t3_r4,
    "ci_pipelines"."updated_at" AS t3_r5,
    "ci_pipelines"."tag" AS t3_r6,
    "ci_pipelines"."yaml_errors" AS t3_r7,
    "ci_pipelines"."committed_at" AS t3_r8,
    "ci_pipelines"."project_id" AS t3_r9,
    "ci_pipelines"."status" AS t3_r10,
    "ci_pipelines"."started_at" AS t3_r11,
    "ci_pipelines"."finished_at" AS t3_r12,
    "ci_pipelines"."duration" AS t3_r13,
    "ci_pipelines"."user_id" AS t3_r14,
    "ci_pipelines"."lock_version" AS t3_r15,
    "ci_pipelines"."auto_canceled_by_id" AS t3_r16,
    "ci_pipelines"."pipeline_schedule_id" AS t3_r17,
    "ci_pipelines"."source" AS t3_r18,
    "ci_pipelines"."config_source" AS t3_r19,
    "ci_pipelines"."protected" AS t3_r20,
    "ci_pipelines"."failure_reason" AS t3_r21,
    "ci_pipelines"."iid" AS t3_r22,
    "ci_pipelines"."merge_request_id" AS t3_r23,
    "ci_pipelines"."source_sha" AS t3_r24,
    "ci_pipelines"."target_sha" AS t3_r25,
    "ci_pipelines"."external_pull_request_id" AS t3_r26,
    "ci_pipelines"."ci_ref_id" AS t3_r27,
    "ci_pipelines"."locked" AS t3_r28,
    "scans_security_findings"."id" AS t4_r0,
    "scans_security_findings"."created_at" AS t4_r1,
    "scans_security_findings"."updated_at" AS t4_r2,
    "scans_security_findings"."build_id" AS t4_r3,
    "scans_security_findings"."scan_type" AS t4_r4,
    "scans_security_findings"."info" AS t4_r5,
    "scans_security_findings"."project_id" AS t4_r6,
    "scans_security_findings"."pipeline_id" AS t4_r7,
    "vulnerability_scanners"."id" AS t5_r0,
    "vulnerability_scanners"."created_at" AS t5_r1,
    "vulnerability_scanners"."updated_at" AS t5_r2,
    "vulnerability_scanners"."project_id" AS t5_r3,
    "vulnerability_scanners"."external_id" AS t5_r4,
    "vulnerability_scanners"."name" AS t5_r5,
    "vulnerability_scanners"."vendor" AS t5_r6
FROM
    "security_findings"
    INNER JOIN "security_scans" ON "security_findings"."scan_id" = "security_scans"."id"
    INNER JOIN "ci_builds" ON "security_scans"."build_id" = "ci_builds"."id"
    INNER JOIN "security_scans" "scans_security_findings" ON "scans_security_findings"."id" = "security_findings"."scan_id"
    INNER JOIN "ci_builds" "builds_security_scans" ON "builds_security_scans"."id" = "security_scans"."build_id"
        AND "builds_security_scans"."type" = 'Ci::Build'
    LEFT OUTER JOIN "security_scans" "scans_security_findings_join" ON "scans_security_findings_join"."id" = "security_findings"."scan_id"
    LEFT OUTER JOIN "ci_builds" "builds_security_findings" ON "builds_security_findings"."id" = "scans_security_findings_join"."build_id"
        AND "builds_security_findings"."type" = 'Ci::Build'
    LEFT OUTER JOIN "ci_job_artifacts" ON "ci_job_artifacts"."job_id" = "builds_security_findings"."id"
    LEFT OUTER JOIN "ci_pipelines" ON "ci_pipelines"."id" = "builds_security_findings"."commit_id"
    LEFT OUTER JOIN "vulnerability_scanners" ON "vulnerability_scanners"."id" = "security_findings"."scanner_id"
WHERE
    "ci_builds"."type" = 'Ci::Build'
    AND "ci_builds"."commit_id" = 92
    AND "security_findings"."deduplicated" = TRUE
    AND "ci_builds"."status" = 'success'
    AND ("ci_builds"."retried" = FALSE
        OR "ci_builds"."retried" IS NULL)
    AND "security_scans"."scan_type" = 2
    AND (NOT EXISTS (
            SELECT
                1
            FROM
                "security_scans"
                INNER JOIN "ci_builds" ON "ci_builds"."id" = "security_scans"."build_id"
                    AND "ci_builds"."type" = 'Ci::Build'
                INNER JOIN "projects" ON "projects"."id" = "ci_builds"."project_id"
                INNER JOIN "vulnerability_feedback" ON "vulnerability_feedback"."project_id" = "projects"."id"
            WHERE (vulnerability_feedback.category = (security_scans.scan_type - 1))
            AND "vulnerability_feedback"."feedback_type" = 0
            AND (security_scans.id = security_findings.scan_id)
            AND (vulnerability_feedback.project_fingerprint = security_findings.project_fingerprint)))
AND "security_findings"."id" IN (225, 227, 228)
ORDER BY
    "security_findings"."severity" DESC,
    "security_findings"."confidence" DESC,
    "security_findings"."id" ASC

https://explain.depesz.com/s/U0h6

 Sort  (cost=73.39..73.39 rows=1 width=1957) (actual time=0.122..0.125 rows=0 loops=1)
   Sort Key: security_findings.severity DESC, security_findings.confidence DESC, security_findings.id
   Sort Method: quicksort  Memory: 25kB
   Buffers: shared hit=21
   I/O Timings: read=0.000 write=0.000
   ->  Nested Loop Left Join  (cost=6.92..73.38 rows=1 width=1957) (actual time=0.045..0.048 rows=0 loops=1)
         Buffers: shared hit=15
         I/O Timings: read=0.000 write=0.000
         ->  Nested Loop Left Join  (cost=6.63..70.07 rows=1 width=1904) (actual time=0.044..0.047 rows=0 loops=1)
               Buffers: shared hit=15
               I/O Timings: read=0.000 write=0.000
               ->  Nested Loop Anti Join  (cost=6.06..66.62 rows=1 width=1581) (actual time=0.044..0.047 rows=0 loops=1)
                     Buffers: shared hit=15
                     I/O Timings: read=0.000 write=0.000
                     ->  Nested Loop Left Join  (cost=4.19..55.58 rows=1 width=1581) (actual time=0.044..0.046 rows=0 loops=1)
                           Buffers: shared hit=15
                           I/O Timings: read=0.000 write=0.000
                           ->  Nested Loop Left Join  (cost=3.61..36.57 rows=1 width=1435) (actual time=0.044..0.046 rows=0 loops=1)
                                 Buffers: shared hit=15
                                 I/O Timings: read=0.000 write=0.000
                                 ->  Nested Loop Left Join  (cost=3.03..33.08 rows=1 width=169) (actual time=0.044..0.046 rows=0 loops=1)
                                       Buffers: shared hit=15
                                       I/O Timings: read=0.000 write=0.000
                                       ->  Nested Loop  (cost=2.60..29.63 rows=1 width=161) (actual time=0.043..0.045 rows=0 loops=1)
                                             Buffers: shared hit=15
                                             I/O Timings: read=0.000 write=0.000
                                             ->  Nested Loop  (cost=2.16..26.31 rows=1 width=114) (actual time=0.043..0.045 rows=0 loops=1)
                                                   Buffers: shared hit=15
                                                   I/O Timings: read=0.000 write=0.000
                                                   ->  Nested Loop  (cost=1.58..22.85 rows=1 width=126) (actual time=0.043..0.044 rows=0 loops=1)
                                                         Buffers: shared hit=15
                                                         I/O Timings: read=0.000 write=0.000
                                                         ->  Nested Loop  (cost=1.01..19.33 rows=1 width=122) (actual time=0.043..0.044 rows=0 loops=1)
                                                               Buffers: shared hit=15
                                                               I/O Timings: read=0.000 write=0.000
                                                               ->  Index Scan using security_findings_pkey on public.security_findings  (cost=0.57..8.97 rows=3 width=106) (actual time=0.042..0.042 rows=0 loops=1)
                                                                     Index Cond: (security_findings.id = ANY ('{225,227,228}'::bigint[]))
                                                                     Filter: security_findings.deduplicated
                                                                     Rows Removed by Filter: 0
                                                                     Buffers: shared hit=15
                                                                     I/O Timings: read=0.000 write=0.000
                                                               ->  Index Scan using security_scans_pkey on public.security_scans  (cost=0.43..3.46 rows=1 width=16) (actual time=0.000..0.000 rows=0 loops=0)
                                                                     Index Cond: (security_scans.id = security_findings.scan_id)
                                                                     Filter: (security_scans.scan_type = 2)
                                                                     Rows Removed by Filter: 0
                                                                     I/O Timings: read=0.000 write=0.000
                                                         ->  Index Scan using ci_builds_pkey on public.ci_builds builds_security_scans  (cost=0.58..3.52 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0)
                                                               Index Cond: (builds_security_scans.id = security_scans.build_id)
                                                               Filter: ((builds_security_scans.type)::text = 'Ci::Build'::text)
                                                               Rows Removed by Filter: 0
                                                               I/O Timings: read=0.000 write=0.000
                                                   ->  Index Scan using ci_builds_pkey on public.ci_builds  (cost=0.58..3.45 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0)
                                                         Index Cond: (ci_builds.id = builds_security_scans.id)
                                                         Filter: (((NOT ci_builds.retried) OR (ci_builds.retried IS NULL)) AND ((ci_builds.type)::text = 'Ci::Build'::text) AND (ci_builds.commit_id = 92) AND ((ci_builds.status)::text = 'success'::text))
                                                         Rows Removed by Filter: 0
                                                         I/O Timings: read=0.000 write=0.000
                                             ->  Index Scan using security_scans_pkey on public.security_scans scans_security_findings  (cost=0.43..3.30 rows=1 width=55) (actual time=0.000..0.000 rows=0 loops=0)
                                                   Index Cond: (scans_security_findings.id = security_scans.id)
                                                   I/O Timings: read=0.000 write=0.000
                                       ->  Index Scan using security_scans_pkey on public.security_scans scans_security_findings_join  (cost=0.43..3.45 rows=1 width=16) (actual time=0.000..0.000 rows=0 loops=0)
                                             Index Cond: (scans_security_findings_join.id = security_findings.scan_id)
                                             I/O Timings: read=0.000 write=0.000
                                 ->  Index Scan using ci_builds_pkey on public.ci_builds builds_security_findings  (cost=0.58..3.49 rows=1 width=1274) (actual time=0.000..0.000 rows=0 loops=0)
                                       Index Cond: (builds_security_findings.id = scans_security_findings_join.build_id)
                                       Filter: ((builds_security_findings.type)::text = 'Ci::Build'::text)
                                       Rows Removed by Filter: 0
                                       I/O Timings: read=0.000 write=0.000
                           ->  Index Scan using index_ci_job_artifacts_on_job_id_and_file_type on public.ci_job_artifacts  (cost=0.58..18.85 rows=15 width=146) (actual time=0.000..0.000 rows=0 loops=0)
                                 Index Cond: (ci_job_artifacts.job_id = builds_security_findings.id)
                                 I/O Timings: read=0.000 write=0.000
                     ->  Nested Loop  (cost=1.87..11.04 rows=1 width=48) (actual time=0.000..0.000 rows=0 loops=0)
                           I/O Timings: read=0.000 write=0.000
                           ->  Nested Loop  (cost=1.45..8.90 rows=1 width=18) (actual time=0.000..0.000 rows=0 loops=0)
                                 I/O Timings: read=0.000 write=0.000
                                 ->  Nested Loop  (cost=1.01..6.94 rows=1 width=14) (actual time=0.000..0.000 rows=0 loops=0)
                                       I/O Timings: read=0.000 write=0.000
                                       ->  Index Scan using security_scans_pkey on public.security_scans security_scans_1  (cost=0.43..3.45 rows=1 width=18) (actual time=0.000..0.000 rows=0 loops=0)
                                             Index Cond: (security_scans_1.id = security_findings.scan_id)
                                             I/O Timings: read=0.000 write=0.000
                                       ->  Index Scan using ci_builds_pkey on public.ci_builds ci_builds_1  (cost=0.58..3.49 rows=1 width=8) (actual time=0.000..0.000 rows=0 loops=0)
                                             Index Cond: (ci_builds_1.id = security_scans_1.build_id)
                                             Filter: ((ci_builds_1.type)::text = 'Ci::Build'::text)
                                             Rows Removed by Filter: 0
                                             I/O Timings: read=0.000 write=0.000
                                 ->  Index Only Scan using projects_pkey on public.projects  (cost=0.44..1.96 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=0)
                                       Index Cond: (projects.id = ci_builds_1.project_id)
                                       Heap Fetches: 0
                                       I/O Timings: read=0.000 write=0.000
                           ->  Index Only Scan using vulnerability_feedback_unique_idx on public.vulnerability_feedback  (cost=0.42..2.06 rows=6 width=46) (actual time=0.000..0.000 rows=0 loops=0)
                                 Index Cond: ((vulnerability_feedback.project_id = projects.id) AND (vulnerability_feedback.category = (security_scans_1.scan_type - 1)) AND (vulnerability_feedback.feedback_type = 0))
                                 Heap Fetches: 0
                                 I/O Timings: read=0.000 write=0.000
               ->  Index Scan using ci_pipelines_pkey on public.ci_pipelines  (cost=0.57..3.44 rows=1 width=323) (actual time=0.000..0.000 rows=0 loops=0)
                     Index Cond: (ci_pipelines.id = builds_security_findings.commit_id)
                     I/O Timings: read=0.000 write=0.000
         ->  Index Scan using vulnerability_scanners_pkey on public.vulnerability_scanners  (cost=0.29..3.31 rows=1 width=53) (actual time=0.000..0.000 rows=0 loops=0)
               Index Cond: (vulnerability_scanners.id = security_findings.scanner_id)
               I/O Timings: read=0.000 write=0.000

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Mehmet Emin INAC

Merge request reports

Loading