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

Mashape Analytics URI bug #470

Closed
subnetmarco opened this issue Aug 12, 2015 · 22 comments
Closed

Mashape Analytics URI bug #470

subnetmarco opened this issue Aug 12, 2015 · 22 comments
Labels
idea/new plugin [legacy] those issues belong to Kong Nation, since GitHub issues are reserved for bug reports. task/bug

Comments

@subnetmarco
Copy link
Member

Aug 11 16:29:59 91.202.65.74 Aug 11 23:29:59 8851f804c05e nginx: 2015/08/11 23:29:59 [error] 54#0: [lua] buffer.lua:164: [mashape-analytics] socket server refused the batch. Status: (400) Error: (["[1] har.log.entries.0.request.url must be uri format"]), context: ngx.timer, client: 188.196.56.12, server: 0.0.0.0:8000
@subnetmarco subnetmarco added the idea/new plugin [legacy] those issues belong to Kong Nation, since GitHub issues are reserved for bug reports. label Aug 12, 2015
@SGrondin
Copy link
Contributor

I added better debugging, so now it'll say [1] har.log.entries.0.request.url must be uri format in [whatever] where [whatever] is the incorrect value.

@subnetmarco
Copy link
Member Author

@SGrondin did you deploy your fix? Because the log message is still the same.

@thibaultcha
Copy link
Member

As of today, the error still says:

[3] har.log.entries.0.request.url must be uri format

So there is no way to know what it really contains.

@thibaultcha thibaultcha removed their assignment Aug 20, 2015
@subnetmarco
Copy link
Member Author

Now I can see the URI error properly:

Aug 26 16:16:14 52.18.160.195 Aug 26 23:14:58 ca6a250858df nginx: 2015/08/26 23:14:58 [error] 37#0: [lua] buffer.lua:164: [mashape-analytics] socket server refused the batch. Status: (400) Error: (["[0] har.log.entries.0.request.url must be uri format in 'http://square-core-qa.elasticbeanstalk.com/api/v1/customer/1_0_0/ideapiu/registrationservice/Dimitri/De Franciscis/12345'","[1] har.log.entries.0.request.url must be uri format in 'http://square-core-qa.elasticbeanstalk.com/api/v1/customer/1_0_0/ideapiu/registrationservice/Dimitri/De Franciscis/12345'"]), context: ngx.timer, client: 5.157.103.239, server: 0.0.0.0:8000

and

Aug 26 16:16:14 52.18.160.195 Aug 26 23:14:58 ca6a250858df nginx: 2015/08/26 23:14:58 [error] 37#0: [lua] buffer.lua:164: [mashape-analytics] socket server refused the batch. Status: (400) Error: (["[0] har.log.entries.0.request.url must be uri format in 'http://cart.lmcloud.aws/cart/v1/remove/dKonDHcKn73Z1UFm9TSFRrnmQe2m8RZz/[object Object]'"]), context: ngx.timer, client: 93.33.106.147, server: 0.0.0.0:8000

and

4:16:14.000 PM  
Aug 26 16:16:14 91.202.66.112 Aug 26 23:16:14 bbeb37766863 nginx: 2015/08/26 23:16:14 [error] 52#0: [lua] buffer.lua:164: [mashape-analytics] socket server refused the batch. Status: (400) Error: (["[1] har.log.entries.0.request.url must be uri format in 'http://haproxy.marathon.mesos/spored/article/get/ekskluziv/tuja-scena/foto-ali-voscena-nicki-minaj-dobiva-kar-si-za sluzi.html'"]), context: ngx.timer, client: 91.185.217.224, server: 0.0.0.0:8000

to give a few.

@thibaultcha
Copy link
Member

Here are several values reported as invalid:

http://haproxy.marathon.mesos/spored/article/get/ekskluziv/tuja-scena/foto-ali-voscena-nicki-minaj-dobiva-kar-si-za sluzi.html
http://square-core-qa.elasticbeanstalk.com/api/v1/customer/1_0_0/ideapiu/registrationservice/Dimitri/De Franciscis/12345
http://cart.lmcloud.aws/cart/v1/remove/dKonDHcKn73Z1UFm9TSFRrnmQe2m8RZz/[object Object]

Any idea why? Maybe the space? I will check the validation code later.

@thibaultcha
Copy link
Member

It is visibly the space (see the regex). I will encode the URI but lua-nginx only offers escape_uri which is meant for URI components, and destroys the URI, so that will probably have to be custom.

@thibaultcha
Copy link
Member

On a second thought, I am not sure I should touch the URI at all. After all, it is the client who requested it without escaping it (and using [] which are reserved characters). I feel like the socket should accept those values, as they might not be valid URIs, but that is what was requested and as an API provider, I want to see those erroneous requests (and potentially reach out to my users to point the issue to them). @SGrondin @ahmadnassri thoughts as mashape analytics maintainers?

@ahmadnassri
Copy link
Contributor

this is more of a HAR format / JSON validation issue than it is Mashape analytics ... we could expand the allowed character set ... maybe

actually surprised nginx even allows it?

@subnetmarco
Copy link
Member Author

So does this issue bounce back to @SGrondin (or @kennethklee)?

@ahmadnassri
Copy link
Contributor

bounce back to you first, do you want to follow the RFC specs or not?

@thibaultcha
Copy link
Member

It's not so much about the specs. The client did not respect the specs, we have to reflect it in the analytics logs.

@ahmadnassri
Copy link
Contributor

that I agree with, and I believe latest build has error logging output in
detail on the server

@thibaultcha
Copy link
Member

No, I meant the logs stored by analytics. I mean on analytics' dashboard.

@ahmadnassri
Copy link
Contributor

but we are discarding the input if its invalid ... not storing anywhere, so no way to message the user about it ... is that what you mean? otherwise I'm not following

@thibaultcha
Copy link
Member

I mean you should not discard it, and you should store it.

@ahmadnassri
Copy link
Contributor

that could become very dangerous since clients are paying for analytics data retention and storage, if somebody is sending malformed requests they could easily take over a user's quota and flood the system ..

that said, this conversation is about Analytics then, so lets take the discussion there, unless there's something specific to Kong, otherwise, lets close this issue,

@thibaultcha
Copy link
Member

They would not take more space because of accepting invalid URIs. They could as well flood the system with valid URIs?

@thibaultcha
Copy link
Member

Moved to Mashape Analytics.

@ahmadnassri
Copy link
Contributor

actually, all of the examples provided above of the errors are because of the space in the URL, not the [] characters ... seems like the analytics plugin in Kong is not properly parsing & encoding the URI before setting it in the JSON object.

@ahmadnassri ahmadnassri reopened this Aug 27, 2015
@thibaultcha
Copy link
Member

Damn it, ngx_lua returns those values unescaped. And the only way to escape them back is with escape_uri which break the URI (also escaping / separating components)

@ahmadnassri
Copy link
Contributor

Damn it, ngx_lua returns those values unescaped. And the only way to escape them back is with escape_uri which break the URI (also escaping / separating components)

I had the same problem with Node / PHP ... I end up parsing and re-constructing the URI every time to be safe.

@thibaultcha
Copy link
Member

So while writing the serializer I respected the ALF schema (where request.url does not contain the querystring) but the HAR specs do contain the querystring.

Hence I used ngx.var.uri -> without the querystring (but unescaped). If we just use request_uri, it contains the querystring but it is the raw URI, as made by the client.

thibaultcha added a commit that referenced this issue Aug 27, 2015
Fix invalid ALFs when the URI contains reserved characters because
`request_uri` returns an unescaped string. `uri` returns the string
untouched but with querystring, which is fine for HAR.

Fix #470
hutchic added a commit that referenced this issue Jun 10, 2022
* fix(proto): add the include directory

* fix(bc): keep the change backwards compatible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea/new plugin [legacy] those issues belong to Kong Nation, since GitHub issues are reserved for bug reports. task/bug
Projects
None yet
Development

No branches or pull requests

4 participants