Fix: Prevent local file access via photo field using magic bytes#601
Fix: Prevent local file access via photo field using magic bytes#601alpernae wants to merge 9 commits intorendercv:mainfrom
photo field using magic bytes#601Conversation
…servation, and image/contact field validation.
photo field using magic bytes
|
This is already better but I would think about using an already well-tested and known package for the role of detecting the actual mime type instead of reinventing the weel... After a quick search I found the following to be the most appetizing options (always imo):
These were just 2 cents, since I hate having to maintain something that someone already worked hard to do and it is for sure more tested and used than my version... 😄 @sinaatalay what do you think? It is for sure lighter to just add the code rather than using an external package, but maybe for the future it is better to use a package and just focus on using the result instead of the implementation. |
|
Hi @sinaatalay, How would you like to proceed here? |
|
@alpernae in the meantime can you pls fix the failing test? This way @sinaatalay would have everything ready |
Added a comment indicating that the issue should be fixed.
|
@LukeSavefrogs All issues should be fixed now. |
|
Thank you. Could you provide an example of how a bad actor might exploit this vulnerability, and what the consequences would be? |
|
Hi @sinaatalay, A security policy with a supported versions table helps users clearly understand which releases address known vulnerabilities (such as the local file exposure issue) and when they should upgrade. This is especially important for a CLI tool, where users may not update automatically. From a project perspective, documenting your security process demonstrates a good-faith effort to handle vulnerabilities responsibly. It can also reduce legal risk and minimize noise from duplicate or scattered reports. A clear policy directs researchers to the appropriate reporting channel instead of having security concerns posted publicly. Most importantly, when users evaluate RenderCV, seeing an active security policy signals competence and care—particularly when there is a known file exposure issue on record. The policy itself doesn’t fix the vulnerability, but it gives you control over how issues are reported, handled, and communicated.
Being a CLI application doesn’t eliminate risk. Since the project is open source, anyone can download and use it publicly or integrate it into internal services (for example, allowing users to generate CVs). In such scenarios, if user input is not properly validated, a malicious actor could supply a crafted file path. If they also have access to directories containing generated CVs or related files, this could potentially lead to unintended file exposure. |
cff31ca to
2b08030
Compare
Summary
This PR addresses the local file access vulnerability by implementing file type validation for the
cv.photofield. Instead of restricting paths (597) to the input directory (which limits user flexibility), this approach validates that the referenced file is actually a valid image by checking its magic bytes.Changes
src/rendercv/schema/models/path.pyAdded:
IMAGE_SIGNATURESconstant: Magic byte signatures forPNG, JPEG, GIF, BMP, WebP, andTIFFformats.is_valid_image_file(path)function: Validates a file is an image by reading and checking its first 12 bytes against known signatures.validate_image_path(path, info)function: Combines path resolution with image format validation.ExistingImagePathRelativeToInputtype alias: New Pydantic-annotated type for image-specific path validation.src/rendercv/schema/models/cv/cv.py
Modified:
photofield type fromExistingPathRelativeToInputtoExistingImagePathRelativeToInputRelated Issues