Commit 68c68249 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'feature/gb/unsafe-regexp-logger' into 'master'

Log usage of ruby regexps into application log

See merge request gitlab-org/gitlab!78458
parents f88de08a 08b10ced
---
name: ci_unsafe_regexp_logger
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78458
rollout_issue_url:
milestone: '14.8'
type: ops
group: group::pipeline authoring
default_enabled: true
...@@ -35,7 +35,10 @@ module Gitlab ...@@ -35,7 +35,10 @@ module Gitlab
# patterns can be matched only when branch or tag is used # patterns can be matched only when branch or tag is used
# the pattern matching does not work for merge requests pipelines # the pattern matching does not work for merge requests pipelines
if pipeline.branch? || pipeline.tag? if pipeline.branch? || pipeline.tag?
if regexp = Gitlab::UntrustedRegexp::RubySyntax.fabricate(pattern, fallback: true) regexp = Gitlab::UntrustedRegexp::RubySyntax
.fabricate(pattern, fallback: true, project: pipeline.project)
if regexp
regexp.match?(pipeline.ref) regexp.match?(pipeline.ref)
else else
pattern == pipeline.ref pattern == pipeline.ref
......
...@@ -20,13 +20,13 @@ module Gitlab ...@@ -20,13 +20,13 @@ module Gitlab
!!self.fabricate(pattern, fallback: fallback) !!self.fabricate(pattern, fallback: fallback)
end end
def self.fabricate(pattern, fallback: false) def self.fabricate(pattern, fallback: false, project: nil)
self.fabricate!(pattern, fallback: fallback) self.fabricate!(pattern, fallback: fallback, project: project)
rescue RegexpError rescue RegexpError
nil nil
end end
def self.fabricate!(pattern, fallback: false) def self.fabricate!(pattern, fallback: false, project: nil)
raise RegexpError, 'Pattern is not string!' unless pattern.is_a?(String) raise RegexpError, 'Pattern is not string!' unless pattern.is_a?(String)
matches = pattern.match(PATTERN) matches = pattern.match(PATTERN)
...@@ -38,6 +38,16 @@ module Gitlab ...@@ -38,6 +38,16 @@ module Gitlab
raise unless fallback && raise unless fallback &&
Feature.enabled?(:allow_unsafe_ruby_regexp, default_enabled: false) Feature.enabled?(:allow_unsafe_ruby_regexp, default_enabled: false)
if Feature.enabled?(:ci_unsafe_regexp_logger, type: :ops, default_enabled: :yaml)
Gitlab::AppJsonLogger.info(
class: self.class.name,
regexp: pattern.to_s,
fabricated: 'unsafe ruby regexp',
project_id: project&.id,
project_path: project&.full_path
)
end
create_ruby_regexp(matches[:regexp], matches[:flags]) create_ruby_regexp(matches[:regexp], matches[:flags])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment