CVE-2023-36456
Unverified X-Forwarded-For and X-Real-IP headers in authentik (prior to 2023.4.3 and 2023.5.5)
- CVSS 7.3
- CWE-436 Interpretation Conflict
- Authentication, Authorization, and Session Management
- Remote
authentik is an open-source Identity Provider. Prior to versions 2023.4.3 and 2023.5.5, authentik does not verify the source of the X-Forwarded-For and X-Real-IP headers, both in the Python code and the go code. Only authentik setups that are directly accessible by users without a reverse proxy are susceptible to this. Possible spoofing of IP addresses in logs, downstream applications proxied by (built in) outpost, IP bypassing in custom flows if used. This poses a possible security risk when someone has flows or policies that check the user's IP address, e.g. when they want to ignore the user's 2 factor authentication when the user is connected to the company network. A second security risk is that the IP addresses in the logfiles and user sessions are not reliable anymore. Anybody can spoof this address and one cannot verify that the user has logged in from the IP address that is in their account's log. A third risk is that this header is passed on to the proxied application behind an outpost. The application may do any kind of verification, logging, blocking or rate limiting based on the IP address, and this IP address can be overridden by anybody that want to. Versions 2023.4.3 and 2023.5.5 contain a patch for this issue.
- CVSS base score
- 7.3
- Published
- 2023-07-06
- OWASP
- A07 Identification and Authentication Failures
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Authentication, Authorization, and Session Management
- Subcategory
- Insecure Authentication Mechanisms
- Accessibility scope
- Remote
- Impact
- Unauthorized Access
- Fixed by upgrading
- Yes
Solution
Update to authentik versions 2023.4.3 or 2023.5.5 or higher.
Vulnerable code sample
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/some_endpoint', methods=['GET'])
def some_endpoint():
client_ip = request.headers.get('X-Forwarded-For', request.remote_addr)
print(f"Client IP: {client_ip}")
return jsonify({"client_ip": client_ip}), 200
if __name__ == '__main__':
app.run()Patched code sample
from flask import Flask, request, jsonify
import ipaddress
app = Flask(__name__)
def get_client_ip():
x_forwarded_for = request.headers.get('X-Forwarded-For')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0].strip()
else:
ip = request.remote_addr
if validate_ip(ip):
return ip
else:
return None
def validate_ip(ip):
try:
ipaddress.ip_address(ip)
return True
except ValueError:
return False
@app.route('/some_endpoint', methods=['GET'])
def some_endpoint():
client_ip = get_client_ip()
if client_ip:
return jsonify({"client_ip": client_ip}), 200
else:
return jsonify({"error": "Invalid IP address"}), 400
if __name__ == '__main__':
app.run()Cite this entry
@misc{vaitp:cve202336456,
title = {{Unverified X-Forwarded-For and X-Real-IP headers in authentik (prior to 2023.4.3 and 2023.5.5)}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-36456},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-36456/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
