Skip to content

Conversation

@Rishi-source
Copy link

@Rishi-source Rishi-source commented Jan 24, 2025

Implement vulnerable package filtering functionality in package search

Fixes : #1759

Feature Added:

  1. Vulnerable package filtering in package search
  2. Ability to filter packages as vulnerable-only, non-vulnerable-only, or all packages

Changes Made:

  1. Updated PackageSearch view in views.py
  2. Modified PackageSearchForm in forms.py
  3. Updated packages.html template with dropdown for vulnerability filtering
  4. Updated PackageV2ViewSet view in api_v2.py

Feature Added:

  1. Vulnerable package filtering in package search
  2. Ability to filter packages as vulnerable-only, non-vulnerable-only, or all packages

Tests Added:

  1. Added test in test_api_v2.py and test_view.py to test the filter.


Screenshot 2025-04-20 at 9 07 17 AM

Signed-off-by: Rishi Garg rishigarg2503@gmail.com

@Rishi-source Rishi-source force-pushed the Vuln branch 2 times, most recently from c8d7dea to 8fc0661 Compare February 16, 2025 06:20
Signed-off-by: Rishi Garg <rishigarg2503@gmail.com>
@Rishi-source
Copy link
Author

Hi @TG1999 , please review this Pull request.

@keshav-space
Copy link
Member

@Rishi-source your code change and PR description do not add up, these things are nowhere to be found in the diff.

Tests Added:

  1. test_package_search_vulnerable_only_filter in PackageSearchTestCase
  2. Validates creation of vulnerable and non-vulnerable packages
  3. Checks vulnerability relationship creation

Changes Made:

  1. Updated PackageSearch view in views.py
  2. Modified PackageSearchForm in forms.py
  3. Updated packages.html template with dropdown for vulnerability filtering
  4. Added JavaScript to handle URL parameter updates for vulnerability filter

@Rishi-source
Copy link
Author

Rishi-source commented Apr 18, 2025

the tests are not added because first I want to get the implementation to get reviewed .previously they where added but Apologies for not removing the test part from the description after I have removed them from the code changes.

@Rishi-source
Copy link
Author

I’ll update the description I have changed the code in the PR but forgotten to change the previous description

Copy link
Member

@keshav-space keshav-space left a comment

Choose a reason for hiding this comment

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

Thanks @Rishi-source, see suggestions below. Also, add tests for these changes.

is_vulnerable = is_vulnerable.lower() == "true"
queryset = queryset.filter(is_vulnerable=is_vulnerable)

queryset = queryset.exclude(version="")
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this?

Copy link
Author

Choose a reason for hiding this comment

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

In the UI, (and likely also in the API), I would welcome an option to filter only vulnerable or non vulnerable packages when doing a search for packages.

the issue description quotes if the same thing can be implemented in the API so I have added it in the API as well.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I get that we need filter in the API, but what I'm trying to understand is whether we need this queryset = queryset.exclude(version="").

Comment on lines 21 to 28
<form method="get" style="display: inline;">
{% if search %}<input type="hidden" name="search" value="{{ search }}">{% endif %}
<select name="vulnerable_only" class="select" id="vulnerable-select" onchange="this.form.submit()">
<option value="">All Packages</option>
<option value="true" {% if request.GET.vulnerable_only == 'true' %}selected{% endif %}>Vulnerable Only</option>
<option value="false" {% if request.GET.vulnerable_only == 'false' %}selected{% endif %}>Non-Vulnerable Only</option>
</select>
</form>
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is how we want to have filters, how about a filter icon to the left with drop-down with All, Non-vulnerable, Vulnerable options.

Copy link
Author

Choose a reason for hiding this comment

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

Sure would add that as well.

Comment on lines 67 to 68
if hasattr(self, "request"):
vulnerable_only = self.request.GET.get("vulnerable_only", "").lower()
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be much cleaner to use a form instead?

Copy link
Author

Choose a reason for hiding this comment

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

Yes It would be clean as well as safer from XSS attacks.. would handle it from form.

Signed-off-by: RISHI GARG <134256793+Rishi-source@users.noreply.github.com>
Signed-off-by: RISHI GARG <134256793+Rishi-source@users.noreply.github.com>
Signed-off-by: RISHI GARG <134256793+Rishi-source@users.noreply.github.com>
Signed-off-by: RISHI GARG <134256793+Rishi-source@users.noreply.github.com>
Signed-off-by: RISHI GARG <134256793+Rishi-source@users.noreply.github.com>
@Rishi-source
Copy link
Author

@keshav-space I have addressed the review points and I have added tests can you please review the changes again and let me know if any other thing is needed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to filter only vulnerable or non vulnerable packages

3 participants