CVE-2021-23772: Link Following in Iris
Summary
CVE-2021-23772: Directory traversal in github.com/kataras/iris and github.com/kataras/iris/v12. Affects github.com/kataras/iris/v12 versions < 12.2.0-alpha8. Fixed in 12.2.0-alpha8. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The package under scrutiny is github.com/kataras/iris, a Go package that provides a fast, simple, and efficient framework for building web applications. It is widely used in the Go ecosystem and offers various features such as routing, middleware, and template rendering. However, all versions of the package are vulnerable to a link following vulnerability. This vulnerability arises from the unsafe handling of file names during file uploads using the UploadFormFiles method. Attackers can exploit this vulnerability to write files to arbitrary locations outside the designated target folder.
Vulnerability Detail
The link following vulnerability in Iris allows attackers to manipulate file names during file uploads, potentially leading to the writing of files in unintended locations. By crafting malicious file names, attackers can bypass the intended target folder and write files to arbitrary locations on the system. This can result in unauthorized access, data leakage, and potential remote code execution. The vulnerability has a CVSS score of 7.5, indicating a high severity level.
How To Fix
Minimum fixed version
12.2.0-alpha8
This is the first release that contains the fix.
go get github.com/kataras/iris/v12@v12.2.0-alpha8
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, developers can implement additional validation and sanitization checks on file names during file uploads. This can include restricting the allowed characters, length, and file extensions. By enforcing strict validation, the risk of link following attacks can be mitigated. Here is an example of how to implement file name validation in Go:
func validateFileName(fileName string) bool {
// Implement your validation logic here
// Return true if the file name is valid, false otherwise
}
func uploadFileHandler(ctx iris.Context) {
file, err := ctx.FormFile("file")
if err != nil {
// Handle error
return
}
fileName := file.Filename
if !validateFileName(fileName) {
// Handle invalid file name
return
}
// Proceed with file upload
}
Conclusion
The link following vulnerability in Iris can have severe consequences, including unauthorized access, data leakage, and potential remote code execution. It is crucial to update to the latest fixed versions of the package to address this vulnerability. Additionally, implementing strict file name validation and sanitization checks can provide temporary mitigation. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for github.com/kataras/iris/v12 →
FAQ
The vulnerability allows attackers to write files to arbitrary locations outside the intended target folder. This can lead to unauthorized access, data leakage, and potential remote code execution.
For github.com/kataras/iris, all versions up to 0.0.2 are affected. For github.com/kataras/iris/v12, all versions up to 12.2.0-alpha8 are affected.
You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability. Vulert monitors and alerts in real-time for open-source vulnerabilities without requiring access to the code or installation.
Yes, the vulnerability is fixed in version 0.0.3 for github.com/kataras/iris and version 12.2.0-alpha9 for github.com/kataras/iris/v12. It is recommended to update to the latest fixed versions.
As a temporary workaround, you can implement additional validation and sanitization checks on file names during file uploads. This can help mitigate the risk of link following attacks.