Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The request object handles auth headers incorrectly #12480

Closed
sergeyklay opened this issue Dec 17, 2016 · 4 comments
Closed

The request object handles auth headers incorrectly #12480

sergeyklay opened this issue Dec 17, 2016 · 4 comments
Assignees
Labels
bug A bug report status: medium Medium
Milestone

Comments

@sergeyklay
Copy link
Contributor

sergeyklay commented Dec 17, 2016

Expected and Actual Behavior

I would like to see correct Authorization Headers in case of use such types of authorization:

  • Basic
  • Digest
  • Bearer

Minimal script to reproduce the issue:

Setup

$di = new Phalcon\Di();

$di->set('filter', function () {
    return new Phalcon\Filter();
});

$request = new Phalcon\Http\Request();
$request->setDI($di);

Test 1

$_SERVER = [
    'PHP_AUTH_USER' => 'phalcon',
    'PHP_AUTH_PW'   => 'secret',
];

print_r($request->getHeaders());

Actual

Array
(
)

Expected

Array
(
    [Php-Auth-User] => phalcon
    [Php-Auth-Pw] => secret
    [Authorization] => Basic cGhhbGNvbjpzZWNyZXQ=
)

Test 2

$_SERVER = [
    'HTTP_AUTHORIZATION' => 'Basic cGhhbGNvbjpzZWNyZXQ=',
];

print_r($request->getHeaders());

Actual

Array
(
    [Authorization] => Basic cGhhbGNvbjpzZWNyZXQ=
)

Expected

Array
(
    [Authorization] => Basic cGhhbGNvbjpzZWNyZXQ=
    [Php-Auth-Pw] => secret
    [Php-Auth-User] => phalcon
)

Test 3

$auth = [
    'username="admin"',
    'realm="The batcave"',
    'nonce=49938e61ccaa4',
    'uri="/"',
    'response="98ccab4542f284c00a79b5957baaff23"',
    'opaque="d8ea7aa61a1693024c4cc3a516f49b3c"',
    'qop=auth',
    'nc=00000001',
    'cnonce="8d1b34edb475994b"'
];

$_SERVER = [
    'REDIRECT_HTTP_AUTHORIZATION' => 'Digest ' . implode(', ', $auth),
];

print_r($request->getHeaders());

Actual

Array
(
)

Expected

Array
(
    [Php-Auth-Digest] => Digest username="admin", realm="The batcave", nonce=49938e61ccaa4, uri="/", response="98ccab4542f284c00a79b5957baaff23", opaque="d8ea7aa61a1693024c4cc3a516f49b3c", qop=auth, nc=00000001, cnonce="8d1b34edb475994b"
    [Authorization] => Digest username="admin", realm="The batcave", nonce=49938e61ccaa4, uri="/", response="98ccab4542f284c00a79b5957baaff23", opaque="d8ea7aa61a1693024c4cc3a516f49b3c", qop=auth, nc=00000001, cnonce="8d1b34edb475994b"
)

Test 4

$accessToken = 'some-secret-token-here';

$_SERVER = [
    'HTTP_AUTHORIZATION' => "Bearer {$accessToken}",
];

print_r($request->getHeaders());

Actual

Array
(
)

Expected

Array
(
    [Authorization] => Bearer some-secret-token-here
)

And yes, as described in RFC 7230 - "Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing", Section 3.2, "Header Fields":

Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.

we can safely return either Php-Auth-User, or PHP-AUTH-USER, or php-auth-user.

Details

  • Phalcon version: 3.0.2
  • PHP Version: 7.0.13
  • Operating System: Ubuntu 14.04.5 LTS
  • Installation type: Compiling from source
  • Zephir version (if any): 0.9.5a-dev
  • Server: Nginx | Apache
@sergeyklay
Copy link
Contributor Author

Fixed in the 3.0.x branch.

@quickshiftin
Copy link

quickshiftin commented May 18, 2018

I'm still encountering this issue in 3.3.1. Essentially $phalconRequest->getAllHeaders() is getallheaders() minus the Authorization header.

@sergeyklay
Copy link
Contributor Author

@quickshiftin Did you see tests at tests/unit/Http/Request/AuthHeaderTest.php

@quickshiftin
Copy link

@sergeyklay I'm looking at it now, and your patch from 3.0.x. It looks like Phalcon does some introspection of the Authorization header's value, and I suspect that's where it's breaking down in my case.

I'm using JWT, so my Authorization headers look like

Authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJleHAiOjE1MzAxMDY3MjQsImlzcyI6InNlbGxlcnZ1ZS1qd3Qt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dBiPfpPErHeO3ee9b6nTvQ_9I_5oOcif7SGM2BiNyTq64Or3V3Yhdr8sEQVwafi4kxJD7eghSLWxy-3WAOvND4Q8R555cHZZvYnwiQePsFNub_04KNwq_Ve2oEPWeI4QiPH8aXdiObjP1ow

I see some logic in there to handle bearer, but it's not working. Maybe if I find time one of these days I'll run the unit tests against my headers and figure out what's wrong.

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants