Commit graph

34 commits

Author SHA1 Message Date
Ankush Menat
394a5ff9ff
fix: Round of rate limit to seconds (#31674) 2025-03-12 10:52:42 +00:00
s-aga-r
f040fb446c
fix: allow multiple @rate_limit decorators to be considered (#31209) 2025-02-11 15:09:34 +05:30
Ankush Menat
bada7cab13
perf: No need to set expiry for rate limiter key everytime (#28956)
* perf: No need to set expiry for key everytime

* fix: Set expiry on first request and never again

This prevents problem of rate limiter keys growing constantly.
2024-12-30 07:31:47 +00:00
Ankush Menat
3ab2c2fbcf
perf: speedup rate limiter by ~1.2x (#28920)
* perf: reuse current time

now_datetime is site-tz-aware, we don't need it here.

* perf: dont need redis transactions

* perf: use `time.time()` instead of datetime

Using `datetime.timestamp()` is a round-about way to use `time.time()`
with extra cost of dealing with datetime and timezones.

* perf: define slots for rate_limiter

* fix!: Remove used rate limit header

This just shares how much was consumed in current request, people can
just time requests to get an approximation for this, not sure why is this
useful.
2024-12-26 10:57:46 +00:00
Gavin D'souza
c6580b5880
refactor: Replace pytz to std lib zoneinfo & datetime
Signed-off-by: Gavin D'souza <gavin.dsouza@switchup.de>
2024-12-06 15:43:33 +05:30
Akhil Narang
ad0a9106de
fix(rate_limiter): we can't call str.join([]) with NoneTypes in the list
Default to an empty string for `user_key`

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-08-22 14:25:03 +05:30
Akhil Narang
0af673a571
fix(rate_limiter): prevent KeyError if the key isn't defined in form_dict
Use dict.get(), it'll just return `None` if the key isn't present
(also will handle a `None` key just fine)

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-08-22 10:47:32 +05:30
Ankush Menat
ea45d959b3 fix: correct HTTP response code for rate limit 2024-04-08 18:24:38 +05:30
Akhil Narang
3f1e19de85
refactor(treewide): enable RUF rules
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-21 16:20:28 +05:30
Ankush Menat
a25e68a763
fix: make rate_limiter respect multitenancy (#24634)
* fix: make rate_limiter respect multitenancy

* fix: lower rate limit window for password reset

* refactor: Use redis_wrapper
2024-01-31 09:16:27 +00:00
Hussain Nagaria
8d2137c265 docs: consistent doc strings 2023-12-18 18:27:39 +05:30
Akhil Narang
fbc88a4d24
refactor(treewide): code cleanup
Drop redundant bool conversion

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2023-11-23 13:57:51 +05:30
Ankush Menat
f526054ae2
refactor: Remove usage of utcnow (#23369) 2023-11-23 13:21:27 +05:30
Ankush Menat
530c47ffe5
feat: after_response callback manager (#22398)
* feat: `after_response` callback manager

* perf: defer closing DB connection

* refactor: simplify after response hooks

* wip

* example usage

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>

* fix: Log request end if not already

---------

Co-authored-by: Sagar Vora <sagar@resilient.tech>
2023-09-14 10:56:08 +00:00
Sagar Vora
3f3821befb fix: dont use form_dict & frappe.call 2023-08-05 13:02:50 +05:30
Sagar Vora
4931c7379c fix: only rate limit if frappe.request is set 2023-08-05 12:54:34 +05:30
Ankush Menat
adf30693a9 ci: update pyupgrade 2023-07-14 14:24:08 +05:30
Ankush Menat
fa6dc03cc8
refactor: frappe.cache() usage to frappe.cache (#21282) 2023-06-08 11:47:17 +05:30
Ankush Menat
81b37cb7d2
refactor: clean up code to py310 supported features (#17367)
refactor: clean up code to py39+ supported syntax

- f-strings instead of format
- latest typing support instead of pre 3.9 TitleCase
- remove UTF-8 declarations.
- many more changes

Powered by https://github.com/asottile/pyupgrade/ + manual cleanups
2022-07-01 11:51:05 +05:30
Suraj Shetty
c0c5b2ebdd
style: format all python files using black (#16453)
Co-authored-by: Frappe Bot <developers@frappe.io>
2022-04-12 10:59:25 +05:30
Leela vadlamudi
3f212fbc7a
Merge pull request #14087 from shadrak98/rate-limiting
feat: Introduce rate-limiting for web forms
2021-09-21 08:07:26 +05:30
shadrak gurupnor
b057a07259 fix(minor): code clean up 2021-09-15 16:07:03 +05:30
shadrak gurupnor
851778e561 fix(minor): sider issues 2021-09-15 07:41:03 +05:30
shadrak gurupnor
930dddc558 fix: test cases for web forms 2021-09-14 21:19:27 +05:30
shadrak gurupnor
5343b28ab5 fix: expiry was not setting on key 2021-09-09 22:35:32 +05:30
shadrak gurupnor
5cc437aa6b feat: made key optional and added IP flag 2021-09-07 19:45:00 +05:30
Gavin D'souza
3446026555 chore: Update header: license.txt => LICENSE
The license.txt file has been replaced with LICENSE for quite a while
now. INAL but it didn't seem accurate to say "hey, checkout license.txt
although there's no such file". Apart from this, there were
inconsistencies in the headers altogether...this change brings
consistency.
2021-09-03 12:02:59 +05:30
shadrak gurupnor
f3bc29cbdc feat: applied rate-limiting on web-forms to avoid bulk submission 2021-09-01 21:03:55 +05:30
Suraj Shetty
9781fb758f fix: Rate limiter to allow kwargs 2021-08-20 22:06:50 +05:30
Gavin D'souza
e407b78506 chore: Drop dead and deprecated code
* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
2021-05-26 15:31:29 +05:30
leela
de210260a7 refactor: allow callable limit arg for ratelimit deco
As we make all configurations editable through dashboard(ex: password_reset_limit), it makes sense
to provide limit as a callable so that it can be accessed dynamically.
2021-03-09 13:59:49 +05:30
leela
ba16e4737b refactor: rate limiter decorator added
We have rate limiter for reset passowrd alone and it is not re-usable
for other endpoints. Added a generic rate limiter decorator that can be
used for any endpoint.
2021-03-09 13:53:00 +05:30
Aditya Hase
aef567fdde fix(rate-limiter): Remove duplicate headers 2020-05-13 13:45:55 +05:30
Aditya Hase
ba7227ab08 feat: Rate Limiter 2020-05-13 12:34:07 +05:30