bednee / cooluri

GIT repository for TYPO3 extension CoolUri
7 stars 12 forks source link

AJAX-calls not working on multidomain-configuration #1

Open schmdt opened 10 years ago

schmdt commented 10 years ago

There is an issue with cooluri intercepting successfulls ajax-calls using eID-mechanism when using multi-domain.

Every call using eID result in an infinite redirect loop.

bednee commented 10 years ago

Can you be more specific and e.g. paste a network log that you could get from Chrome dev console (press F12).

Thanks

Jan

Dne 29. 7. 2014 13:47, Daniel Schmidt napsal(a):

There is an issue with cooluri intercepting successfulls ajax-calls using eID-mechanism when using multi-domain.

Every call using eID result in an infinite redirect loop.

— Reply to this email directly or view it on GitHub https://github.com/bednee/cooluri/issues/1.Web Bug from https://github.com/notifications/beacon/6805379__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyMjI1MzYzOCwiZGF0YSI6eyJpZCI6MzgyNDkyOTd9fQ==--38b2ad7c939211a7c048c2248a3f1ba4c812d5d0.gif

schmdt commented 10 years ago

Sure.

Configuration is as follows:

tx_cooluri_enable       = 1
redirectOldLinksToNew   = 1
$TYPO3_CONF_VARS['EXT']['extConf']['cooluri'] = 'a:3:{s:6:"LANGID";s:1:"L";s:7:"XMLPATH";s:10:"typo3conf/";s:11:"MULTIDOMAIN";s:1:"1";}';

When sending ajax requests to anything like ?eID=xyz TYPO3 responds with 301 again and again which results in browser error net::ERR_TOO_MANY_REDIRETS.

I've attached a log-screen, but in short:

"response": {
          "status": 301,
          "statusText": "Moved Permanently",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Pragma",
              "value": "no-cache"
            },
            {
              "name": "Date",
              "value": "Tue, 29 Jul 2014 12:30:20 GMT"
            },
            {
              "name": "Server",
              "value": "Apache"
            },
            {
              "name": "X-Powered-By",
              "value": "PHP/5.5.9"
            },
            {
              "name": "Transfer-Encoding",
              "value": "chunked"
            },
            {
              "name": "Connection",
              "value": "Keep-Alive"
            },
            {
              "name": "Content-Type",
              "value": "text/html"
            },
            {
              "name": "Location",
              "value": "http://ml-recode.dev/?eID=ptxAjax&extensionName=cycustomers&pluginName=Showrandomoffer&controllerName=Offer&actionName=showAjaxRandomOffer&addparams=a:8:{s:10:%22editOwnPid%22;s:3:%22246%22;s:10:%22ownlistPid%22;s:3:%22245%22;s:10:%22ownshowPid%22;s:3:%22433%22;s:7:%22onlytop%22;s:1:%220%22;s:26:%22excludeTaggingFromInstance%22;s:1:%220%22;s:6:%22groups%22;s:1:%222%22;s:8:%22branches%22;s:7:%22250,254%22;s:13:%22showCaroussel%22;i:1;}&_=1406637020418"
            },
            {
              "name": "Cache-Control",
              "value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
            },
            {
              "name": "Set-Cookie",
              "value": "fe_typo_user=bc90cba8484393f1038b3400cb397429; path=/"
            },
            {
              "name": "Keep-Alive",
              "value": "timeout=5, max=92"
            },
            {
              "name": "Expires",
              "value": "Thu, 19 Nov 1981 08:52:00 GMT"
            }
          ],
          "cookies": [
            {
              "name": "fe_typo_user",
              "value": "bc90cba8484393f1038b3400cb397429",
              "path": "/",
              "expires": null,
              "httpOnly": false,
              "secure": false
            }
          ],
          "content": {
            "size": 0,
            "mimeType": "text/html",
            "compression": 0
          },
          "redirectURL": "http://ml-recode.dev/?eID=ptxAjax&extensionName=cycustomers&pluginName=Showrandomoffer&controllerName=Offer&actionName=showAjaxRandomOffer&addparams=a:8:{s:10:%22editOwnPid%22;s:3:%22246%22;s:10:%22ownlistPid%22;s:3:%22245%22;s:10:%22ownshowPid%22;s:3:%22433%22;s:7:%22onlytop%22;s:1:%220%22;s:26:%22excludeTaggingFromInstance%22;s:1:%220%22;s:6:%22groups%22;s:1:%222%22;s:8:%22branches%22;s:7:%22250,254%22;s:13:%22showCaroussel%22;i:1;}&_=1406637020418",
          "headersSize": 890,
          "bodySize": 0
        },

The responses redirect-url matches the one of the original request, leading to the loop.

20140729-143626

I already researched and fixed the error (see the connected pull request).

In class.tx_cooluri.php->goForRedirect() the first condition decides if redirect is neccessary by checking if URI contains either index.php or '?'. In that case the url will be translated by looking for the respective page. The translation cant be resolved as there is no id (page-id) param in the url, therefore the redirect gets the original url.

I've added a statement to the condition && !stripos(t3lib_div::getIndpEnv('REQUEST_URI'),'eID=') checking if eID is present.

bednee commented 10 years ago

Hi,

I thought about it, and I don't think that this needs fixing. I'm more thinking that there's something wrong with your setup. I'm using eID in a few projects with CoolUri and I've never had any issues regarding CoolUri.

Could you turn on DevLog? There's some debugging which could be helpful.

Jan

Dne 29. 7. 2014 14:45, Daniel Schmidt napsal(a):

Sure.

Configuration is as follows:

tx_cooluri_enable = 1 redirectOldLinksToNew = 1

$TYPO3_CONF_VARS['EXT']['extConf']['cooluri'] = 'a:3:{s:6:"LANGID";s:1:"L";s:7:"XMLPATH";s:10:"typo3conf/";s:11:"MULTIDOMAIN";s:1:"1";}';

When sending ajax requests to anything like |?eID=xyz| TYPO3 responds with 301 again and again which results in browser error |net::ERR_TOO_MANY_REDIRETS|.

I've attached a log-screen, but in short:

"response": { "status": 301, "statusText": "Moved Permanently", "httpVersion": "HTTP/1.1", "headers": [ { "name": "Pragma", "value": "no-cache" }, { "name": "Date", "value": "Tue, 29 Jul 2014 12:30:20 GMT" }, { "name": "Server", "value": "Apache" }, { "name": "X-Powered-By", "value": "PHP/5.5.9" }, { "name": "Transfer-Encoding", "value": "chunked" }, { "name": "Connection", "value": "Keep-Alive" }, { "name": "Content-Type", "value": "text/html" }, { "name": "Location", "value": "http://ml-recode.dev/?eID=ptxAjax&extensionName=cycustomers&pluginName=Showrandomoffer&controllerName=Offer&actionName=showAjaxRandomOffer&addparams=a:8:{s:10:%22editOwnPid%22;s:3:%22246%22;s:10:%22ownlistPid%22;s:3:%22245%22;s:10:%22ownshowPid%22;s:3:%22433%22;s:7:%22onlytop%22;s:1:%220%22;s:26:%22excludeTaggingFromInstance%22;s:1:%220%22;s:6:%22groups%22;s:1:%222%22;s:8:%22branches%22;s:7:%22250,254%22;s:13:%22showCaroussel%22;i:1;}&_=1406637020418" }, { "name": "Cache-Control", "value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0" }, { "name": "Set-Cookie", "value": "fe_typo_user=bc90cba8484393f1038b3400cb397429; path=/" }, { "name": "Keep-Alive", "value": "timeout=5, max=92" }, { "name": "Expires", "value": "Thu, 19 Nov 1981 08:52:00 GMT" } ], "cookies": [ { "name": "fe_typouser", "value": "bc90cba8484393f1038b3400cb397429", "path": "/", "expires": null, "httpOnly": false, "secure": false } ], "content": { "size": 0, "mimeType": "text/html", "compression": 0 }, "redirectURL": "http://ml-recode.dev/?eID=ptxAjax&extensionName=cycustomers&pluginName=Showrandomoffer&controllerName=Offer&actionName=showAjaxRandomOffer&addparams=a:8:{s:10:%22editOwnPid%22;s:3:%22246%22;s:10:%22ownlistPid%22;s:3:%22245%22;s:10:%22ownshowPid%22;s:3:%22433%22;s:7:%22onlytop%22;s:1:%220%22;s:26:%22excludeTaggingFromInstance%22;s:1:%220%22;s:6:%22groups%22;s:1:%222%22;s:8:%22branches%22;s:7:%22250,254%22;s:13:%22showCaroussel%22;i:1;}&=1406637020418", "headersSize": 890, "bodySize": 0 },

The responses redirect-url matches the one of the original request, leading to the loop.

20140729-143626 https://cloud.githubusercontent.com/assets/1384727/3734838/033961ca-171d-11e4-9caf-1692852eff54.png

I already researched and fixed the error (see the connected pull request).

In |class.tx_cooluri.php->goForRedirect()| the first condition decides if redirect is neccessary by checking if URI contains either index.php or '?'. In that case the url will be translated by looking for the respective page. The translation cant be resolved as there is no id (page-id) param in the url, therefore the redirect gets the original url.

I've added a statement to the condition |&& !stripos(t3lib_div::getIndpEnv('REQUEST_URI'),'eID=')| checking if eID is present.

— Reply to this email directly or view it on GitHub https://github.com/bednee/cooluri/issues/1#issuecomment-50470952.Web Bug from https://github.com/notifications/beacon/6805379__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyMjI1NzEzOSwiZGF0YSI6eyJpZCI6MzgyNDkyOTd9fQ==--ca8a1e393250468905b21090e7cce38d7d16ccc4.gif

mbrodala commented 10 years ago

I think this is a valid issue and basically the same as this one: https://forge.typo3.org/issues/52329

The suggested fix is to disable redirects for eID processing.

In our case issues appear because we are on an HTTPs page, an AJAX call is performed to the same page but with ?id=<pid> which results in a redirect by CoolURI to the human-readable version but with HTTP. Normally now TYPO3 would jump in and redirect this to HTTP but the browser already stops processing since loading HTTP content in HTTPS context is not allowed. In a nutshell:

  1. Be on https://example.org/foo/ (= pid 42)
  2. Trigger AJAX request to https://example.org/index.php?eID=...&id=42
  3. Cache hit in CoolURI
  4. Redirect to http://example.org/foo/?eID=...
  5. Browser stops here
  6. TYPO3 would redirect to https://example.org/foo/?eID=...

The issue seems to stem from Link_Func::redirect() where it looks like every redirect is done via http.

bednee commented 10 years ago

Hey,

do you have redirectOldToNew turned on? This can cause it.

Jan

Dne 20. 10. 2014 11:12, mbrodala napsal(a):

I think this is a valid issue and basically the same as this one: https://forge.typo3.org/issues/52329

The suggested fix is to disable redirects for eID processing.

In our case issues appear because we are on an HTTPs page, an AJAX call is performed to the same page but with |?id=| which results in a redirect by CoolURI to the human-readable version but with HTTP. Normally now TYPO3 would jump in and redirect this to HTTP but the browser already stops processing since loading HTTP content in HTTPS context is not allowed. In a nutshell:

  1. Be on |https://example.org/foo/| (= pid 42)
  2. Trigger AJAX request to |https://example.org/index.php?eID=...&id=42|
  3. Cache hit in CoolURI
  4. Redirect to |http://example.org/foo/?eID=...|
  5. Browser stops here
  6. TYPO3 would redirect to |https://example.org/foo/?eID=...|

The issue seems to stem from |Link_Func::redirect()| where it looks like every redirect is done via http.

— Reply to this email directly or view it on GitHub https://github.com/bednee/cooluri/issues/1#issuecomment-59712692.Web Bug from https://github.com/notifications/beacon/6805379__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyOTQxNTU3NCwiZGF0YSI6eyJpZCI6MzgyNDkyOTd9fQ==--b8f083010ce2c0c4e1d3486cd3ef77e86d90fb12.gif

{"@context":"http://schema.org","@type":"EmailMessage","description":"View this Issue on GitHub","action":{"@type":"ViewAction","url":"https://github.com/bednee/cooluri/issues/1#issuecomment-59712692","name":"View Issue"}}

mbrodala commented 10 years ago

@bednee Yes, of course that option is turned on and it needs to be enabled for regular activities.

stylefish commented 9 years ago

hey dudes, this also causes problems on normal requests to the index site (ERR_TOO_MANY_REDIRECTS) when you run this site with forced https (301 permanent redirect) and are trying to supply url parameters to the index page (/) e.g. https://mydomain/?myparameter=123. this would cause an infinite loop due to this line $url = 'http://' . $url[0] . '/' . $url[1]; in the "goForRedirect" funtion. so maybe you want to fix this, although i dont know what the "redirectOldToNew" does. for me turning it off fixed the issue. greetings