Skip to content
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

show link to symlink target on analysis page #1282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jstucke
Copy link
Collaborator

@jstucke jstucke commented Oct 15, 2024

No description provided.

@jstucke jstucke requested a review from maringuu October 15, 2024 16:02
@jstucke jstucke self-assigned this Oct 15, 2024
@jstucke jstucke force-pushed the link-symlink-target branch from 270b8d8 to 24cf135 Compare October 29, 2024 10:09
Copy link
Collaborator

@maringuu maringuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I am hesitating to merge this as FACT's internals are not really built with support for symlinks in mind as can be seen by the above comments.
Of course, this feature is useful and desirable, but not possible to implement correctly atm.
I'll leave it to you or @dorpvom to merge this.

Comment on lines +486 to +487
for uid in session.execute(query.limit(1)).scalars():
return uid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware that we, by design, can not get this right, but I'd just like to note that using limit(1) to get a random target file is not necessarily correct.

Copy link
Collaborator Author

@jstucke jstucke Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, there should only be one result at this point (but there may be so weird edge cases that I haven't thought of)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To elaborate a bit on the underlying idea: at this point we know the root FW of the file and the path that is mentioned in the file type ("link to '/a/b/c'). The idea is to look in the "virtual path" for paths that line up with this. Usually, this should be only one file. But there are two other possibilities: the file is missing from the file system or there are multiple file systems or containers with this path contained in the firmware. In the latter case, there isn't really a right or wrong result, since the file object represents all of these files at once. We could display all link targets, though.

Comment on lines 247 to 243
full_type = file_obj.processed_analysis['file_type']['result']['full']
# if FO is a symlink, file_type analysis "full" will be something like "symbolic link to 'busybox'"
target_path = full_type.split("'")[1]
except (IndexError, KeyError):
return None
Copy link
Collaborator

@maringuu maringuu Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, we can't really do much about this, but this prone to be broken.
For example, it does not work with the link created by ln -s "./crash'es" "foo'bar".
Furthermore, I'd like to note that this is actually not standard file output,
but defined in src/install/internal_symlink_magic.

Edit: You could parse the file according to the logic defined in internal_symlink_magic which would be a bit more correct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prone to be broken

This is a bit of an overstatement. I have yet so to come across a file with a single quote in its file name in a firmware image. And even if that happened, we would simply not find the linked file and nothing more would break. Nevertheless, I changed the code so that it won't break even in this case.

{{ firmware.uid | replace_uid_with_hid(root_uid=root_uid) | safe }}<br />
{{ firmware.uid | replace_uid_with_hid(root_uid=root_uid) | safe }}
{% if link_target %}
({{ link_target | safe }})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not safe:

printf "\n" > '<script>alert("injection");'
ln -s \<script\>alert\(\"injection\"\)\; foobar

tar -cvf x.tar ./*

While this does not run altert, it still breaks the whole site.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a html.escape()

@jstucke jstucke force-pushed the link-symlink-target branch from 24cf135 to ea4c2b5 Compare January 9, 2025 09:32
@jstucke jstucke force-pushed the link-symlink-target branch from ea4c2b5 to e255107 Compare January 9, 2025 09:38
@jstucke jstucke requested a review from dorpvom January 9, 2025 09:57
@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2025

Codecov Report

Attention: Patch coverage is 85.71429% with 6 lines in your changes missing coverage. Please review.

Project coverage is 91.85%. Comparing base (ab95ac5) to head (e255107).

Files with missing lines Patch % Lines
src/web_interface/components/analysis_routes.py 71.42% 4 Missing ⚠️
src/storage/db_interface_frontend.py 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1282      +/-   ##
==========================================
- Coverage   92.48%   91.85%   -0.63%     
==========================================
  Files         379      378       -1     
  Lines       24115    21163    -2952     
==========================================
- Hits        22302    19440    -2862     
+ Misses       1813     1723      -90     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants