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

Fix unstable JS challange passing #1077

Merged
merged 4 commits into from
Oct 22, 2018
Merged

Fix unstable JS challange passing #1077

merged 4 commits into from
Oct 22, 2018

Conversation

vankoven
Copy link
Contributor

@vankoven vankoven commented Oct 10, 2018

Related to JS challenge issue described in #1074

  • Synchronize computation of delay in JS Challange between JS and Tempesta code
  • Don't close client connection if unchallenged resources was requested before JS challenge is passed. Blocking of clients that makes too many requests with incorrect cookie values is subject for Sessions rate limit #598 .

@krizhanovsky @aleksostapenko Please, test this fix in your environment. I could reproduce the issue, but I couldn't reproduce the exact behaviour you had.

- Fix incorrect calculation of allowed time frame for a new request.
'delay_range' was stored in Tempesta in jiffies while it was used
in msecs in JS code. That could lead to defferent calculation results
on TempestaFW and client.
- Don't close connection, if non-chalengeable resource was requested
before passing JS challenge.
Copy link
Contributor

@aleksostapenko aleksostapenko left a comment

Choose a reason for hiding this comment

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

Good for me, with minor comments.

* @delay_limit - maximum timeout between client's requests to pass the
* challenge, in jiffies;
* @delay_range - allowed time range for client to make a repeated request,
* in msecs;
Copy link
Contributor

@aleksostapenko aleksostapenko Oct 19, 2018

Choose a reason for hiding this comment

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

Perhaps maximum range for random timeout added to delay_min or something like that would be more appropriate description for delay_range field (the same for Wiki).

}
if (limit < min_limit) {
else if (tfw_cfg_js_ch->delay_limit < min_limit) {
TFW_WARN_NL("%s: delay limit is too low, "
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just exit with configuration error here? It seems that min_limit is too small value for tfw_cfg_js_ch->delay_limit anyway, and will lead to rejections of legitimate clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was a requirement of the JS Challenge task: #536 (comment)

Configuration process must enforce the value to be greater than delay_range + delay_min and show warning if it's less than delay_range + delay_min + 100. Default value is delay_range + delay_min + 1000 (enough ever fro cross atlantic connections and relatively slow hardware and software).

The last moment of time browser can send a request - delay_range + delay_min, and some time is required to deliver the request. min_limit adds extra 0.1s. Yes, this configuration is not very reliable: delivering via cross-Atlantic is slower, browsers can be slow, etc., while default limit (+1s) is reliable enough. But user may want to use less or more strict time lines and we should honour his choices.


if (!tfw_cfg_js_ch)
return 0;

cur_time = jiffies;
min_time = sv->ts + tfw_cfg_js_ch->delay_min
+ sv->ts % tfw_cfg_js_ch->delay_range;
+ msecs_to_jiffies(sv->ts % tfw_cfg_js_ch->delay_range);
Copy link
Contributor

@aleksostapenko aleksostapenko Oct 19, 2018

Choose a reason for hiding this comment

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

I see, that this non-trivial time calculation is intended for consistency with calculations in js_challenge.js.tpl, but an explanatory comment would be appropriate here.

@vankoven vankoven merged commit 074e73d into master Oct 22, 2018
@vankoven vankoven deleted the ik-fix-jsc branch October 22, 2018 14:17
@@ -121,18 +121,23 @@ static struct kmem_cache *sess_cache;
/**
* JavaScript challenge.
*
* To pass JS challenge client must repeat it's request in exact time frame
Copy link
Contributor

Choose a reason for hiding this comment

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

its?

@@ -150,7 +155,7 @@ static const unsigned short tfw_cfg_redirect_st_code_dflt = 302;
* 'Accept: text/html' and GET method.
*/
static bool
tfw_http_sticky_redirect_allied(TfwHttpReq *req)
tfw_http_sticky_redirect_apllied(TfwHttpReq *req)
Copy link
Contributor

Choose a reason for hiding this comment

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

applied?


if (!tfw_cfg_js_ch)
return 0;

cur_time = jiffies;
/*
* When a client calculates it's own random delay, it uses range value
Copy link
Contributor

Choose a reason for hiding this comment

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

its?

@vankoven
Copy link
Contributor Author

@i-rinat Thank you for comments! The PR is already merged, but I'll fix this in my next PR.

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.

3 participants