Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,761
    • Issues 44,761
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,330
    • Merge requests 1,330
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #33569
Closed
Open
Issue created Oct 07, 2019 by Joern Schneeweisz@joernchenDeveloper

Open Redirect in `InternalRedirect`

Summary

Within app/controllers/concerns/internal_redirect.rb the safe_redirect_path method is intended to assure that no external redirects occur:


module InternalRedirect
  extend ActiveSupport::Concern

  def safe_redirect_path(path)
    return unless path
    # Verify that the string starts with a `/` and a known route character.
    return unless path =~ %r{^/[-\w].*$}

    uri = URI(path)
    # Ignore anything path of the redirect except for the path, querystring and,
    # fragment, forcing the redirect within the same host.
    full_path_for_uri(uri)
  rescue URI::InvalidURIError
    nil
  end

The check return unless path =~ %r{^/[-\w].*$} however is bypassable as the regular expression uses ^ and $ as anchors. Those anchors match by line and can be satisfied by single lines within multi-line input e.g.:

not-starting-with-a-slash
/starting/with/a/slash

Steps to reproduce

The following URL demonstrates the issue and will redirect to gitlab.com.phishingsite.bugkraut.de:

https://gitlab.com/joernchen/xxeserve/-/import?continue[to]=.phishingsite.bugkraut.de?%0a/path

Possible fixes

Replacing the regex anchors by \A and \z will catch newlines and fix this issue. I've got a patch and some test for it ready, I'm just waiting for my dev.gitlab.org access to push those.

Assignee
Assign to
Time tracking