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

Implementation of the ability to send js challenge according with custom rules. #2131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

biathlon3
Copy link
Contributor

No description provided.

@biathlon3 biathlon3 linked an issue Jun 7, 2024 that may be closed by this pull request
@biathlon3 biathlon3 force-pushed the ag_2104-implement-ability-to-send-js-challenge-according-custom-rules branch from 30ffc30 to 14766c3 Compare June 7, 2024 11:13
Copy link
Contributor

@enuribekov-tempesta enuribekov-tempesta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@biathlon3 biathlon3 force-pushed the ag_2104-implement-ability-to-send-js-challenge-according-custom-rules branch from acbebd6 to f920564 Compare July 23, 2024 07:03
@EvgeniiMekhanik EvgeniiMekhanik requested a review from const-t July 29, 2024 12:11
@@ -499,6 +503,10 @@ tfw_cfgop_http_rule(TfwCfgSpec *cs, TfwCfgEntry *e)
rule->act.type = TFW_HTTP_MATCH_ACT_CACHE_TTL;
rule->act.cache_ttl = act_val_parsed;
}
else if (!strcasecmp(action, "jsch")) {
is_jsch_global = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is inconsistent behavior - you change global variable only if one jsch is set.
For example:
config = """
http_chain {
host == "aaa" -> jsch;
host == "bbb" -> good;
}

If host == "aaa" ->jsch is set we don't support js challenge for "bbb". But if it is not set we support it! Why? How host == "aaa" -> jsch; deal with host "bbb"?

if (test_bit(TFW_HTTP_B_HAS_STICKY, req->flags))
return 0;
return tfw_http_sticky_add(resp, cache);
if (req->need_jsch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called for all types of cookies which are set by tempesta. It is not only about js_challenge, so this check is wrong

switch (tfw_http_sess_obtain(req)) {
case TFW_HTTP_SESS_SUCCESS:
break;
if (req->need_jsch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check here is wrong. tfw_http_sess_obtain called not only because of js challenge! see cookie learned. I add new tests for it.

*/
BUG_ON(r < __TFW_HTTP_SESS_PUB_CODE_MAX);
return tfw_http_sticky_challenge_start(req);
if (req->need_jsch) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is wrong here. We get cookies for cookie learn also.

@@ -666,6 +668,8 @@ tfw_http_sess_check_jsch(StickyVal *sv, TfwHttpReq* req)
{
unsigned long min_time;
TfwCfgJsCh *js_ch = req->vhost->cookie->js_challenge;
if (!req->need_jsch)
Copy link
Contributor

@EvgeniiMekhanik EvgeniiMekhanik Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please combine it with the next check in one if

@@ -156,6 +156,10 @@ tfw_http_tbl_scan(TfwMsg *msg, TfwHttpTable *table, TfwHttpActionResult *action)
return 0;
case TFW_HTTP_MATCH_ACT_BLOCK:
return -1;
case TFW_HTTP_MATCH_ACT_JSCH:
action->type = TFW_HTTP_RES_JSCH;
action->vhost = tfw_vhost_lookup_default();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its wrong. I add test to check it.
http_chain {{
uri == "*1.html" -> jsch;
host == "good" -> good;
-> default;
}}

For such configuration if host is good and uri == "*1.html" it should go to good vhost not default!

Copy link
Contributor

@EvgeniiMekhanik EvgeniiMekhanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to rework. We also need changes in etc/tempesta_fw.conf - descriptions and examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ability to send js challenge according custom rules
3 participants