Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108663 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12680 invoked from network); 19 Feb 2020 07:07:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Feb 2020 07:07:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 89129180539 for ; Tue, 18 Feb 2020 21:23:30 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Feb 2020 21:23:30 -0800 (PST) Received: by mail-qv1-f42.google.com with SMTP id q9so9362965qvu.7 for ; Tue, 18 Feb 2020 21:23:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=OjYdRUzFnzzQIsW4bE01kHUwRrD4pYHqDBwqe8ryda8=; b=HR82+mHFLybYSsJVXmStKIS+VgXSSxOiaavqXmjfG9dxwwmgm7Z2A9QE3D4GK/YlUK cNa6pBuTRIuKFvlhYn2MUcdozGRsUVxdpnv6gsumcZPQjzEr6xRsCg22w2z43h7tJWhI Ng3JqwPYxLTXODVlH6oH1BsN4PwMauARkJa2BPPgdRtX+lsyYVwghPXE9wilMQoCA6+r E1qKc+XgNYOJoVvXvVQENa+4iXMgmiMNg6dTlA3J9h/BK1OuOcelRkcPIvIL/pALhBWm j9JrE0Z/+uQ8aHKLrwimv1wb/1NVC3vteV/grLL4Mi4/z8cpm7ZziOpeH4Q4wMr7si1r m3HA== X-Gm-Message-State: APjAAAVKwJFySuCEpSebqb/5xE/My+Cf8wxb43eHE83AALvz0dpWcuhA gD31rcDVJTPrFN3qpVNLFUwtiiY6woELj0ob/iI= X-Google-Smtp-Source: APXvYqzx10H7wQRBmYJEd5pJNgzbIiU/0INWoJSi7kzMlU+wLyZcTPwdRIIMKip52A3iqfBaJtdtm400L3wn5swi4iU= X-Received: by 2002:a0c:f485:: with SMTP id i5mr19937409qvm.8.1582089806239; Tue, 18 Feb 2020 21:23:26 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: bishop@php.net Date: Wed, 19 Feb 2020 00:22:50 -0500 Message-ID: To: Craig Francis Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000e75d9a059ee6fc86" Subject: Re: [PHP-DEV] $_FILES['name'] check From: bishop@php.net (Bishop Bettini) --000000000000e75d9a059ee6fc86 Content-Type: text/plain; charset="UTF-8" On Sun, Feb 16, 2020 at 6:24 PM Craig Francis wrote: > Just to check, at the moment, if I was an evil hacker, and was to run: > > curl -F 'file=@example.jpg;filename=../../../example.php' > https://example.com/upload/ > > The $_FILES['file']['name'] would be set to "example.php", where PHP has > removed the leading "../../../" (good to see). > > Does that happen simply because of this IE fix, where it uses _basename() > in the PHP source: > > > https://github.com/php/php-src/blob/0b4778c377a5753a0deb9cfc697d4f62acf93a29/main/rfc1867.c#L1144 Mostly, it seems. _basename will either be php_ap_basename[1] or php_mb_rfc1867_basename[2], and both of those handle the base name functionality regardless of platform. The comment's a little misleading, though. The original implementation[3] had a magic quotes check when compiled under WIN32, and that's what the comment's talking about. The comment's not saying that the basename call itself is for Windows only. [1]: https://github.com/php/php-src/blob/0b4778c377a5753a0deb9cfc697d4f62acf93a29/main/rfc1867.c#L558 [2]: https://github.com/php/php-src/blob/2e97ae91c8ac404be00050eef414b555aba45a1c/ext/mbstring/mbstring.c#L852 [3]: https://github.com/php/php-src/blob/7ee1fdb657f2a6da65087552e6dda8cf2f4bd1ef/main/rfc1867.c#L1088 --000000000000e75d9a059ee6fc86--