-
Notifications
You must be signed in to change notification settings - Fork 0
compiling cario code #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
compiling cario code #189
Conversation
5fc32cd to
98d341a
Compare
| .filter_map(Result::ok) | ||
| .filter(|e| e.file_type().is_file() && e.path().extension().map_or(false, |ext| ext == "cairo")) | ||
| { | ||
| let content = fs::read_to_string(entry.path())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semgrep identified an issue in your code:
The application builds a file path from potentially untrusted data, which can lead to a path traversal vulnerability. An attacker can manipulate the path which the application uses to access files. If the application does not validate user input and sanitize file paths, sensitive files such as configuration or user data can be accessed, potentially creating or overwriting files. To prevent this vulnerability, validate and sanitize any input that is used to create references to file paths. Also, enforce strict file access controls. For example, choose privileges allowing public-facing applications to access only the required files.
Dataflow graph
flowchart LR
classDef invis fill:white, stroke: none
classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none
subgraph File0["<b>crates/cairo-compile-utils/src/lib.rs</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/starkware-libs/bootloader-hints/blob/98d341a3e5ffab9a225e8524f4f31e02d54e4b3f/crates/cairo-compile-utils/src/lib.rs#L16 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 16] entry.path()</a>"]
end
%% Intermediate
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/starkware-libs/bootloader-hints/blob/98d341a3e5ffab9a225e8524f4f31e02d54e4b3f/crates/cairo-compile-utils/src/lib.rs#L16 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 16] entry.path()</a>"]
end
end
%% Class Assignment
Source:::invis
Sink:::invis
File0:::invis
%% Connections
Source --> Sink
To resolve this comment:
✨ Commit Assistant fix suggestion
| let content = fs::read_to_string(entry.path())?; | |
| // Ensure the entry's path is within the intended directory to prevent path traversal | |
| if !entry.path().starts_with(project_root) { | |
| continue; // Skip files outside the target directory | |
| } | |
| let content = fs::read_to_string(entry.path())?; |
View step-by-step instructions
- Validate that
entry.path()only points to files within the intended directory (project_root) by checking that the entry's path starts withproject_root. You can do this withentry.path().starts_with(project_root). - Before calling
fs::read_to_string(entry.path()), add a check:
if !entry.path().starts_with(project_root) { continue; } - Alternatively, if you expect only
.cairofiles in a fixed folder, consider filtering out any files with path components like..or symlinks that could point outside the target directory, to prevent path traversal. - Reject or skip any files not meeting the above requirements before processing their contents.
This will make sure your code only reads files in your intended directory and avoids unwanted file access.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by tainted-path.
You can view more details about this finding in the Semgrep AppSec Platform.
Type
Description
Breaking changes?
This change is