Prevent the manipulation of search keyword suggestions

Open
#6,769 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
php
Domain
backend, search

Research direction

Start by tracing SearchHandler::saveKeywordSuggestion() to SearchKeywordAction::registerSearch(), then inspect SearchKeywordAction::getSearchResultList() and the existing keyword storage. Determine how the application identifies guests and users and how it persists per-user search history; the issue does not name those files or tests. Done means guests still search without recording keywords and each registered user's keyword is counted only once.

Written by the indexing model from the issue text.

Description

Problem

Every search query is recorded in wcf1_search_keyword via SearchKeywordAction::registerSearch(). It is called from SearchHandler::saveKeywordSuggestion() and the searches counter goes up by one each time. The data is used for
the keyword suggestions in the search (SearchKeywordAction::getSearchResultList(), ordered by searches DESC).

Nothing limits who can register a keyword or how often, so the suggestions are easy to manipulate:

  • Guests can submit any number of searches without authentication, for example from a script, and push arbitrary terms (spam, offensive content, advertising) to the top of the suggestions shown to everyone.
  • A single registered user can raise a keyword's counter without limit just by repeating the same search.

The daily cleanup in DailyCleanUpCronjob only removes rarely used keywords and does nothing against inflated counters.

Proposed solution

  1. Do not record keywords for guests. registerSearch() should not be called at all for guests. Searches by guests still work as before, they just no longer affect the suggestions.
  2. Count each keyword only once per user. A user's repeated searches for the same keyword must not raise searches again. This needs a way to track which user has already searched for which keyword.
Dominant language
PHP
Stars
248
Forks
147
Avg merge
17m
Merged PRs (30d)
21

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WoltLab/WCF

All issues in WoltLab/WCF

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.