Skip to content

Array-valued info_hash parameter crashes the announce handler #23

Description

@nkboedecker

Summary

A query parameter written as info_hash[]=x is parsed by PHP into an array. The announce handler passes $_GET["info_hash"] straight to bin2hex(), which requires a string:

":hash" => htmlentities(bin2hex($_GET["info_hash"]), ENT_QUOTES),

On PHP 8 this is an uncaught TypeError (a fatal error; the absolute script path is disclosed when display_errors is on). On PHP 7 it is a warning and bin2hex() returns null. Any client can send the request.

Reproduce

curl -s "http://localhost/?info_hash[]=x"

Observed on PHP 8.4:

Fatal error: Uncaught TypeError: bin2hex(): Argument #1 ($string) must be of type string, array given in /var/www/html/index.php:39

On PHP 7.4: Warning: bin2hex() expects parameter 1 to be string, array given.

Fix

A PR follows that guards the parameter with is_string() and returns a bencoded Invalid request reply for non-string input, before it reaches bin2hex().

Found during a review of the codebase; part of the same review as #20.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions