Skip to content

Conversation

hamishforbes
Copy link
Contributor

Currently there's no way to tell if ngx.decode_args, ngx.req.get_uri_args or ngx.req.get_post_args silently discard arguments without enabling debug logging.

This change adds a second boolean return value to indicate if arguments have been truncated.

@agentzh
Copy link
Member

agentzh commented Aug 5, 2015

@hamishforbes An additional return value can break backward compatibility, for example,

foo(ngx.req.get_uri_args(), "some other things")

will not work as expected because the second argument now becomes the 3rd, leading to (kindy) hard-to-debug issues.

We need to figure out a better way without breaking existing user code.

@hamishforbes
Copy link
Contributor Author

Ah, that is a good point, didn't think of that!

We could add another argument that toggles returning this flag, e.g. local args, truncated = ngx.req.get_uri_args(100, true) but thats not particularly elegant either... what do you think?

The main issue is the args get truncated silently which can lead to odd issues when passing on request to other systems.
So maybe just raising the log level of the existing message to error or warn would be sufficient?

I think it would be preferable to allow the user to handle it themselves rather than log something but at least it would be clear what has happened.

@agentzh
Copy link
Member

agentzh commented Aug 6, 2015

@hamishforbes You beat me :)

Another flag argument looks artificial to me as well. I would have a hard time documenting this argument if we implemented it.

Raising default error log level for the logging can open a door for malicious clients to flush your nginx error logs which can be very expensive because error logging is never buffered (for obvious reasons). Maybe adding a new configuration directive to allow the user to change the level? Still a bit cumbersome but a bit better than messing up the Lua API :) What do you think? (Sorry)

@hamishforbes
Copy link
Contributor Author

Do you mean adding an option similar to lua_socket_log_errors?
That sounds reasonable.

The only other approach I can think of would be to add something like ngx.get_last_args_parse_error().
But thats not very nice either and smacks a bit of PHP...

@agentzh
Copy link
Member

agentzh commented Aug 6, 2015

@hamishforbes Oh, seems like there's another way. How about adding an empty metatable to the resulting table in case of truncation? This won't break existing code I suppose and you have a way to handle this case in Lua yourself.

@hamishforbes
Copy link
Contributor Author

I'm not entirely sure I follow, do you mean setting the metatable to {} rather than nil?

@agentzh
Copy link
Member

agentzh commented Aug 6, 2015

@hamishforbes Yes.

@hamishforbes
Copy link
Contributor Author

That sounds like a better solution.

I'm pretty new to the Lua C API but am I right in thinking this is as simple as

lua_newtable(L);
lua_setmetatable(L, top);

@agentzh
Copy link
Member

agentzh commented Aug 7, 2015

@hamishforbes Instead of creating a new table upon every call, we could reuse and share a single empty table. It's supposed to be read-only anyway.

@hamishforbes
Copy link
Contributor Author

Whats the best way to go about doing that? Or is there somewhere else in the codebase you've already used that technique?
Is it as simple as using lua_setglobal and lua_get_global?

@agentzh
Copy link
Member

agentzh commented Aug 7, 2015

@hamishforbes Maybe you can find this helpful: http://www.lua.org/manual/5.1/manual.html#luaL_newmetatable

@hamishforbes
Copy link
Contributor Author

Ah missed that one! Sounds like repeatedly calling luaL_newmetatable doesn't create a new table each time, so that should be fine?

Do you have any preference for naming of metatables like this, there doesn't seem to be any others in the current codebase.

I'll update and push tests/docs if you're happy with this approach.

@agentzh
Copy link
Member

agentzh commented Aug 7, 2015

@hamishforbes Yes. Please go ahead :) Though I'm still not 100% happy with this approach ;)

@hamishforbes
Copy link
Contributor Author

Ok cool, thanks for the pointers!

@mergify
Copy link

mergify bot commented Jun 26, 2020

This pull request is now in conflict :(

@mergify
Copy link

mergify bot commented Mar 20, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 20, 2023
@mergify mergify bot removed the conflict label May 10, 2023
@mergify
Copy link

mergify bot commented May 10, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 10, 2023
@mergify mergify bot removed the conflict label Sep 23, 2023
@mergify
Copy link

mergify bot commented Sep 23, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Sep 23, 2023
@mergify mergify bot removed the conflict label Mar 6, 2024
Copy link

mergify bot commented Mar 6, 2024

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 6, 2024
@mergify mergify bot removed the conflict label May 27, 2024
Copy link

mergify bot commented May 27, 2024

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 27, 2024
@mergify mergify bot removed the conflict label Feb 13, 2025
Copy link

mergify bot commented Feb 13, 2025

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Feb 13, 2025
@mergify mergify bot removed the conflict label May 7, 2025
Copy link

mergify bot commented May 7, 2025

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 7, 2025
@mergify mergify bot removed the conflict label Jul 9, 2025
Copy link

mergify bot commented Jul 9, 2025

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants