Problem/Motivation

There are potential bugs when searching for projects with characters like &

Steps to reproduce

TBD

Proposed resolution

Once #3280721: Create test fixture is in, we should be able to write tests for it.
See ProjectBrowser.svelte for the query string construction

Remaining tasks

  • ✅ File an issue about this project
  • ☐ Addition/Change/Update/Fix to this project
  • ☐ Testing to ensure no regression
  • ☐ Automated unit/functional testing coverage
  • ☐ Developer Documentation support on feature change/addition
  • ☐ User Guide Documentation support on feature change/addition
  • ☐ Code review from 1 Drupal core team member
  • ☐ Full testing and approval
  • ☐ Credit contributors
  • ☐ Review with the product owner
  • ☐ Release

User interface changes

API changes

Data model changes

Release notes snippet

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tim.plunkett created an issue. See original summary.

hooroomoo’s picture

Assigned: Unassigned » hooroomoo

hooroomoo’s picture

Planning to wait till #3281686: Fix incorrect taxonomy term ID in test fixture is in (since it looks like it will be very soon) to rewrite test using the newly introduced helper method from the issue

fjgarlin’s picture

Status: Active » Needs work
hooroomoo’s picture

Assigned: hooroomoo » Unassigned
Status: Needs work » Needs review
fjgarlin’s picture

Status: Needs review » Reviewed & tested by the community

Changes are simple and tests are provided. Marking as RTBC.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

I'm reviewing this. I have a few questions that I'll try to post soon

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work

Why are we doing any XSS filtering on the query string? My understanding is that while it's important to sanitize anything being rendered by us on the front-end, doing string matching should be a 1:1 operation on the input.
For example, consider \Drupal\block\Controller\CategoryAutocompleteController::autocomplete() which does the comparison on the raw string, and only escapes it for storing the matches that will be rendered later.

Unless I'm missing something, I think we should remove those Xss::filter calls, and only escape things if they are being rendered by us, but leave the values intact for the source plugins to do their comparisons.

fjgarlin’s picture

If the data is not manipulated and comes from the front-end it will always be ok. However, the endpoints are open and anybody could query them openly within the project and change the URL.

ie: Request URL: https://SITE-URL/drupal-org-proxy/project?page=0&limit=12&sort=usage_tot...

If we are ok passing the request "as is" to the plugins, then yeah, I guess we can remove all the Xss::filter calls from "ProjectBrowserEndpointController". I was probably being over-cautious.

tim.plunkett’s picture

Assigned: tim.plunkett » hooroomoo

I think we want to do straight comparisons against the user input, no matter how malformed or even malicious it is. It's up to the plugins to handle that (for example, by using the database API, the MockDrupalDotOrg plugin is protected against SQL injection).

Reassigning to @hooroomoo to remove all of the uses of Xss::filter from this method (other places in the module shouldn't need adjusting)

hooroomoo’s picture

Assigned: hooroomoo » Unassigned
Status: Needs work » Needs review
fjgarlin’s picture

Status: Needs review » Reviewed & tested by the community

It looks good to me. All Xss::filter removed from the controller as mentioned in the review and tests provided.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

Merged, thanks!

tim.plunkett’s picture

Status: Fixed » Needs work

Hmm, this caused failures on PHP 8.1
Sorting changed from PHP 7 to 8, but I'm not sure which part of it caused this problem.

Reverted for now, sorry

  • tim.plunkett committed 8c19fe4 on 1.0.x
    Revert "Issue #3281209 by hooroomoo: Test filters and searching with...
fjgarlin’s picture

Assigned: Unassigned » fjgarlin

fjgarlin’s picture

I created a new branch and recreated the changes from the previous MR: https://git.drupalcode.org/project/project_browser/-/merge_requests/97/d...

The new MR is: https://git.drupalcode.org/project/project_browser/-/merge_requests/114/...

The only change compared to the previous is to add the `$ignore_order` parameter to the function that checks that arrays are the same as the order is only relevant when we're testing order of elements. I'm not sure this covers 100% the PHP8.1 case.

fjgarlin’s picture

Running the test in PHP8.1 all is green, but it's not in PHP7.3 (see above). The highlighted difference is:

-    0 => '$?Vitamin&C;'
-    1 => '&Un:/written'
+    0 => '&Un:/written'
+    1 => '$?Vitamin&C;'

I'm not sure if it's the PHP version or the MySQL version tho.

fjgarlin’s picture

As the order is not relevant for this test (and it is related to mysql version, which in turn is really related to how the plugin sorts things) I just changed the placement where the special characters appear.

The rest of the changes should be pretty much as in the original MR.
I'll trigger tests with PHP7.3 and PHP8.1.

fjgarlin’s picture

Status: Needs work » Needs review
hooroomoo’s picture

Status: Needs review » Reviewed & tested by the community

Change looks good to me

fjgarlin’s picture

Assigned: fjgarlin » Unassigned

  • tim.plunkett committed c499d78 on 1.0.x authored by fjgarlin
    Issue #3281209 by hooroomoo, fjgarlin, tim.plunkett: Test filters and...
tim.plunkett’s picture

Status: Reviewed & tested by the community » Fixed

I use sqlite locally, and that was the difference. Queued up sqlite with both MRs and it failed the old one and passed the new one!
Thanks for the fixes.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.