2017 © Pedro Peláez
 

library humbug_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

image

padraic/humbug_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  • Monday, February 12, 2018
  • by padraicb
  • Repository
  • 8 Watchers
  • 83 Stars
  • 1,086,929 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 11 Forks
  • 5 Open issues
  • 10 Versions
  • 7 % Grown

The README.md

humbug_get_contents

Package version Build Status Slack License, (*1)

Defines a Humbug\get_contents() function that will transparently call file_get_contents(), except for HTTPS URIs where it will inject a context configured to enable secure SSL/TLS requests on all versions of PHP 5.3+., (*2)

All versions of PHP below 5.6 not only disable SSL/TLS protections by default, but have most other default options set insecurely. This has led to the spread of insecure uses of file_get_contents() to retrieve HTTPS resources. For example, PHAR files or API requests. Without SSL/TLS protections, all such requests are vulnerable to Man-In-The-Middle attacks where a hacker can inject a fake response, e.g. a tailored php file or json response., (*3)

Installation

composer require padraic/humbug_get_contents

Usage

$content = Humbug\get_contents('https://www.howsmyssl.com/a/check');

You can use this function as an immediate alternative to file_get_contents() in any code location where HTTP requests are probable., (*4)

This solution was originally implemented within the Composer Installer, so this is a straightforward extraction of that code into a standalone package with just the one function. It borrows functions from both Composer and Sslurp., (*5)

In rare cases, this function will complain when attempting to retrieve HTTPS URIs. This is actually the point ;). An error should have two causes:, (*6)

  • A valid cafile could not be located, i.e. your server is misconfigured or missing a package
  • The URI requested could not be verified, i.e. in a browser this would be a red page warning.

Neither is, in any way, a justification for disabling SSL/TLS and leaving end users vulnerable to getting hacked. Resolve such errors; don't ignore or workaround them., (*7)

Headers

You can set request headers, and get response headers, using the following functions. This support is based around stream contexts, but is offered in some limited form here as a convenience. If your needs are going to extend this, you should use a more complete solution and double check that it fully enables and supports TLS., (*8)

// Don't end headers with \r\n when setting via array
Humbug\set_headers([
    'Accept-Language: da',
    'User-Agent: Humbug',
]);

$response = Humbug\get_contents('http://www.example.com');

Request headers are emptied when used, so you would need to reset on each Humbug\get_contents() call., (*9)

To retrieve an array of the last response headers:, (*10)

$response = Humbug\get_contents('http://www.example.com');
$headers = Humbug\get_headers();

Upgrade

Upgrade Guide, (*11)

Contributing

Contribution Guide, (*12)

The Versions

12/02 2018

dev-master

9999999-dev https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

https http ssl download file_get_contents tls

12/02 2018

1.1.2

1.1.2.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

https http ssl download file_get_contents tls

10/07 2017

1.1.1

1.1.1.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

https http ssl download file_get_contents tls

02/06 2017

1.1.0

1.1.0.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

https http ssl download file_get_contents tls

22/04 2015

1.0.4

1.0.4.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

https http ssl download file_get_contents tls

21/03 2015

1.0.3

1.0.3.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

https http ssl download file_get_contents tls

08/03 2015

v1.0.2

1.0.2.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

https http ssl download file_get_contents tls

08/03 2015

1.0.2

1.0.2.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

https http ssl download file_get_contents tls

05/02 2015

1.0.1

1.0.1.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

https http ssl download file_get_contents tls

04/02 2015

1.0.0

1.0.0.0 https://github.com/padraic/file_get_contents

Secure wrapper for accessing HTTPS resources with file_get_contents for PHP 5.3+

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

https http ssl download file_get_contents tls