paragi / sphp

A snappy PHP execution module / middleware
46 stars 14 forks source link

The header content contains invalid characters #5

Closed steffanhalv closed 7 years ago

steffanhalv commented 7 years ago
HP Workers spares: 2  min: 2  Max: 10
0 PID: 3577  State: ready  age: 0.003 Seconds
1 PID: 3576  State: ready  age: 0.015 Seconds
==========================================================================
Deploying worker PID:  3576
_http_outgoing.js:363
      throw new TypeError('The header content contains invalid characters');
      ^
TypeError: The header content contains invalid characters
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:363:13)
    at /home/steffanhalv/cloud-npm-php/node_modules/sphp/sphp.js:108:18
    at Socket.<anonymous> (/home/steffanhalv/cloud-npm-php/node_modules/sphp/sphp.js:578:15)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:153:18)
    at Socket.Readable.push (_stream_readable.js:111:10)
    at Pipe.onread (net.js:537:20)
npm ERR! Linux 4.10.0-30-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "start"
npm ERR! node v4.7.2
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! cloud-npm-php@1.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cloud-npm-php@1.0.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cloud-npm-php package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cloud-npm-php
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cloud-npm-php
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR!     /home/steffanhalv/cloud-npm-php/npm-debug.log
paragi commented 7 years ago

hmm - never seen that one. I see that you are using an older version of node (v4.7.2) What is your setup? express version? ws version? php-cgi version?

steffanhalv commented 7 years ago

Looks similar to https://github.com/angular/angular-phonecat/issues/303 I now updated everything to latest but receiving same error

"dependencies": {
    "body-parser": "~1.17.1",
    "cookie-parser": "~1.4.3",
    "debug": "~3.0.0",
    "express": "^4.15.4",
    "morgan": "~1.8.1",
    "pug": "~2.0.0-beta11",
    "serve-favicon": "~2.4.2",
    "sphp": "^0.4.3",
    "ws": "^3.1.0"
  }

PHP 7.0.22-0ubuntu0.17.04.1 (cgi-fcgi) (built: Aug  8 2017 22:03:30)

I did also lookup what was sent to callback('header','Location',line[i].substr(div+2)); (Line 578 in sphp.js)

And it looked quiet normal: callback('header','Location','http://35.193.157.4/haagen/index.php');

Its some things I dont understand with the logging, can you please advice me? ->

_http_outgoing.js:507
    throw new TypeError('The header content contains invalid characters');
    ^
TypeError: The header content contains invalid characters
    at validateHeader (_http_outgoing.js:507:11)
    at ServerResponse.setHeader (_http_outgoing.js:511:3)
    at /home/steffanhalv/cloud-npm-php/node_modules/sphp/sphp.js:108:18
    at Socket.<anonymous> (/home/steffanhalv/cloud-npm-php/node_modules/sphp/sphp.js:578:15)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:252:12)
    at readableAddChunk (_stream_readable.js:235:13)
    at Socket.Readable.push (_stream_readable.js:197:10)
    at Pipe.onread (net.js:589:20)

What does response in response.setHeader(data,param); at line 110 in sphp.js refer to?

The variables becomes

var data = 'Location';
var data param = 'http://35.193.157.4/haagen/wp-admin/install.php';

And I tried this test nodejs server on same linux server:

var http = require('http');
http.createServer((req, res) => {
res.setHeader('Location', 'http://35.193.157.4/haagen/wp-admin/install.php');
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hi!');
res.end();
}).listen(80);

Which works just fine and outputs this headers from chrome:

HTTP/1.1 200 OK
Location: http://35.193.157.4/haagen/wp-admin/install.php
Content-Type: text/plain
Date: Fri, 11 Aug 2017 07:34:54 GMT
Connection: keep-alive
Transfer-Encoding: chunked

So doesnt your response.setHeader use nodejs default setHeader?

@paragi

steffanhalv commented 7 years ago

The error did come from /r character.

Fixed by 015b41574531ed8210159fa92afeddf18d3c5795 #6

paragi commented 7 years ago

Thank you for fixing it!

I haver never tried it with PHP 7 or wordpress. (It was intended for embedded systems) How did that go?

The response.setHeader(data,param) in line 108 is buffering and eventually sending http headers to the client. The line you describe is a page redirecting to another page. I'm not familiar with the inner workings of wordpress, but it's not an uncommon thing to do.

At a quick glance i suspect the issue arise from line 568. But I will accept you changes for now, and look deeper into it, at a later time.

Thank you for your effort.

steffanhalv commented 7 years ago

Thank you. I did come to installation page 2 in wp, but then it didnt work to catch $_POST. But $_GET did work ..

I didnt manage to install it because of this and using nginx for now. But I would like to use npm later for development if its possible without big configs etc.

paragi commented 6 years ago

Hi Steffan As mentioned, I didn't expect this package to be used in the manner you described. But I found wordpress to be an interesting test case. I have rewriten the the superglobal part and header handling.

Would you be so kind as to test it against your application? There is a new version at NPM and gitHub.

steffanhalv commented 6 years ago

Hi, I would be glad to :)

This could be useful in the future, I will do when I get free time

Regards Steffan

2017-11-06 0:26 GMT+01:00 Simon Rigét notifications@github.com:

Hi Steffan As mentioned, I didn't expect this package to be used in the manner you described. But I found wordpress to be an interesting test case. I have rewriten the the superglobal part and header handling.

Would you be so kind as to test it against your application? There is a new version at NPM and gitHub.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/paragi/sphp/issues/5#issuecomment-342014858, or mute the thread https://github.com/notifications/unsubscribe-auth/AEYWIJNkyfDf8hWI8RxupDMIGfsw1lB2ks5szkQvgaJpZM4OzpJe .

steffanhalv commented 6 years ago

C:\Users\steff\Desktop\npm\php>npm run dev

php@1.0.0 dev C:\Users\steff\Desktop\npm\php node index.js

C:\Users\steff\Desktop\npm\php\node_modules\sphp\sphp.js:459 throw new Error(str); ^

Error: PHP worker script ended with error. PHP engine: C:\Users\steff\AppData\Local\scoop\apps\php\7.0.12\php-cgi.exe Preburner script: /php_worker.php Error code: 4294967295 at FormDebugMessage (C:\Users\steff\Desktop\npm\php\node_modules\sphp\sphp.js:459:11) at ChildProcess. (C:\Users\steff\Desktop\npm\php\node_modules\sphp\sphp.js:410:9) at ChildProcess.emit (events.js:159:13) at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! php@1.0.0 dev: node index.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the php@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\steff\AppData\Roaming\npm-cache_logs\2017-12-14T03_21_39_381Z-debug.log

C:\Users\steff\Desktop\npm\php>

paragi commented 6 years ago

Still not working for wordpress!

When I try to log in, I get sendt arround there pages: Serving PHP page: /wp-login.php Serving PHP page: /wp-admin//index.php Serving PHP page: /wp-login.php

Last time, the UTL is: http://localhost:8080/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%3A8080%2Fwp-admin%2F&reauth=1

Do you know whats going on with wordpress? Could it be a cookie issue?