Exception: Gitlab::Git::PreReceiveError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/gitlab/git/pre_receive_error.rb

Overview

PreReceiveError is special because its message gets displayed to users in the web UI. Because of this, we:

  • Only display errors that have been marked as safe with a prefix. This is to prevent leaking of stacktraces, or other sensitive info.

  • Sanitize the string of any XSS

Constant Summary collapse

SAFE_MESSAGE_PREFIXES =
[
  'GitLab:', # Messages from gitlab-shell
  'GL-HOOK-ERR:' # Messages marked as safe by user
].freeze
SAFE_MESSAGE_REGEX =
/^(#{SAFE_MESSAGE_PREFIXES.join('|')})\s*(?<safe_message>.+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', fallback_message: '') ⇒ PreReceiveError

Returns a new instance of PreReceiveError.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitlab/git/pre_receive_error.rb', line 21

def initialize(message = '', fallback_message: '')
  @raw_message = message

  sanitized_msg = sanitize(message)

  if sanitized_msg.present?
    super(sanitized_msg)
  else
    super(fallback_message)
  end
end

Instance Attribute Details

#raw_messageObject (readonly)

Returns the value of attribute raw_message.



19
20
21
# File 'lib/gitlab/git/pre_receive_error.rb', line 19

def raw_message
  @raw_message
end