Commit graph

262 commits

Author SHA1 Message Date
18alantom
db4a7504e5
fix: add hooks to handle cors 2025-07-04 13:18:43 +05:30
18alantom
1215afdf96
feat(OAuth2): support RFC 9728
adds OAuth Settings to configure settings pertaining to Frappe used as
an OAuth auth server and resource server
2025-07-03 13:20:52 +05:30
18alantom
4cd8115c4c
refactor: unify how .well-known routes are handled 2025-07-02 15:17:42 +05:30
18alantom
f8425b6520
feat(OAuth2): support RFC 8414
This allows an OAuth client to get metadata about the auth server, i.e.
the frappe bench being used as an OAuth2 auth server.

Metadata includes values for auth server urls and endpoints and
supported types and modes.
2025-07-01 13:40:18 +05:30
Sagar Vora
d190e07cfa
fix: restore earlier werkzeug request default (#33145) 2025-06-28 12:15:52 +05:30
Ankush Menat
0613f4b11f
fix: Update session after request (#33136) 2025-06-27 13:42:22 +05:30
Sagar Vora
b857a4099a perf: use orjson for faster request processing 2025-06-26 17:37:51 +05:30
Ankush Menat
b57eb60486
perf: chain db transactions (#33004)
* perf: chain transactions

Frequently used rollback/commits can be modified to chain previous
transaction.

This reduces one query to DB in most requests.

* perf: chain transactions in requests
2025-06-19 12:37:39 +05:30
Sagar Vora
f833e4e21b
fix: improve flow to rollback db transaction when processing requests (#32980)
* fix: improve flow to rollback db transaction when processing requests

* fix: rollback, log request and process response for HTTPException
2025-06-18 16:27:46 +05:30
Sagar Vora
f62bae6f5a
refactor: reduce branching in init_request (#32981) 2025-06-18 10:01:20 +05:30
Sagar Vora
5d5092d6ae fix: limit profiler output to 200 lines 2025-03-20 08:37:51 +05:30
Sagar Vora
60b889c3b8 fix: ensure correct context in sys.exc_info 2025-02-19 17:33:53 +05:30
Sagar Vora
f4062b4d7a fix: ensure consistent error in response 2025-02-19 12:10:59 +05:30
Ankush Menat
e16f3b1c84
fix: set default, don't override cache headers (#31306)
Oof.
2025-02-19 11:28:34 +05:30
Ankush Menat
d9081f170b
feat: HTTP caching on API endpoints (#29997)
* fix: update instead of extend

None of these are supposed to be extended over defaults.

* feat: custom response header support

* refactor: use response_headers to set cache control headers

* feat: Decorator to cache API response using cache-control headers

* perf: cache notifications for 1 minute

+ SWR for 5 minutes

* perf: cache `get_events` on desk load

* perf: slow down auto-refresh even more

once every 5 seconds instead of 2 seconds.

* perf: Cache plain link validation for 30 minutes

Very often you're picking same documents again and again, there's no
need to validate them.

Also, document is JUST selected using search_link, so it's 99%
guaranteed to be valid.

The real purpose of this function is to provide "fetch from" feature,
not link validation like the name suggests.

It will get validated server side anyway.

* fix: Never use HTTP cache in developer mode

* perf: cache "is_document_amended"

A document that is amended from something stays amended.

* perf: proxy-cache website_script.js

* fix: only cache if called directly
2025-01-24 20:04:57 +05:30
Ankush Menat
153c38571f fix: Never use HTTP cache in developer mode 2025-01-24 18:58:39 +05:30
Soham Kulkarni
c067fd4b62
fix: remove whitespace from restrict ip and always check request_ip (#29867)
* fix: remove whitespace in restrict ip in validate

* fix: added check for request_ip

* fix: return if no restrict ip

* fix: set to localhost if none, refactor validate_ip_addr

* fix: validate ip_address cleanup and removed uncessary comments

* fix: validate ip_addr cleanup

* fix: remove unecessary check
2025-01-24 13:12:58 +00:00
Ankush Menat
32054b0757 refactor: use response_headers to set cache control headers 2025-01-24 18:35:26 +05:30
Ankush Menat
f30159adc6 feat: custom response header support 2025-01-24 18:35:26 +05:30
Ankush Menat
33d6ea94b8 fix: update instead of extend
None of these are supposed to be extended over defaults.
2025-01-24 18:35:26 +05:30
Ankush Menat
320798d390
perf: add cache-control headers on private files (#29221)
* perf: add cache-control headers on private files

- Client(browser) side cache
- 1 hr expiry
- 1 day revalidation
- etagged by nginx in default config (so no data transfer on expiry still)

In conjunction with https://github.com/frappe/agent/pull/157

* fix: Don't override existing headers
2025-01-17 18:51:34 +05:30
Ankush Menat
430c0c7c7a
fix(DX): Log all exceptions in developer mode (#29195)
ALL exceptions - even validation errors. This is excessive logging but
in development mode it should be fine and even helpful in debugging few
issues.
2025-01-16 15:50:56 +05:30
Ankush Menat
9e8ab92371
refactor: move all optimizations and pre/post fork hooks to separate file (#28832)
Now they will truly execute before/after fork = :pinch: few bytes saved!
2024-12-19 16:46:26 +05:30
Ankush Menat
9d9193800b
fix: Keep HTTP caches private by default (#28719)
Developers can easily enable `can_cache` without knowing what it
entails. Public cache means proxy can likely cache things without
talking to backend.

Obviously many endpoints which can be cached on client side should
probably not be cached in proxy.

E.g. linked PR to the PR that added this feature suggest caching
notification log for short time... we don't want to leak one user's
cached notification to another user.

I don't buy that developers should know about cache implementation to
ensure it's secure or correct to enable it on certain endpoint. In
addition to that, we have very few mechanisms to burst cache
inside proxy. End user hitting ctrl+shift+r won't do anything if proxy
wants to serve stale response.

We should figure out better way to instruct FW about final cache
control headers than hardcoding it IMO.
2024-12-18 14:57:51 +05:30
Akhil Narang
84ef6ec677
refactor: fixup with ruff 0.8.1
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-12-04 13:18:04 +05:30
David Arnold
7e0f281fda
fix: revert etag implementation (#28358) 2024-11-03 11:02:29 +00:00
Rushabh Mehta
6da9d2a808
Merge pull request #28271 from rmehta/fix-oauth-page
fix(style): fix oauth authorisation page and standardise error responses
2024-11-03 10:42:04 +05:30
Gavin D'souza
ecb4795ed3
feat: Enable Sentry Sampling
Closes https://github.com/frappe/frappe/issues/28245
2024-10-28 11:27:51 +01:00
Rushabh Mehta
cef8c12ee4 fix(style): fix oauth authorisation page and standardise error responses 2024-10-24 15:21:34 +05:30
David Arnold
8cfeb156df
devx: add deprecation dumpster (#27887)
* feat: Add deprecation_dumpster.py file

* docs: add jovial and jocose docstring for frappe/deprecation_dumpster.py

* refactor: fill the dumpster with its own kind

* refactor: move to the deprecation dumpster

* chore: color coding class

* fix: only check import error when import errors
2024-10-08 18:56:10 +02:00
David
d87b786687
chore: fix all invocation of init for singledispatch -> min 1 positional arg 2024-09-13 11:53:52 +02:00
David
1619cc0e58
feat: add cache control 2024-08-30 09:08:42 +02:00
Ankush Menat
04642edd63
fix: Move Monitor dump to after_response (#26703)
It needs access to response to capture status code and size etc
2024-06-06 14:38:22 +00:00
Ankush Menat
445e1dbd6b
perf: num2words, babel, gettext, sentry imports (#26475)
num2words - 260KB - Used frequently on ERPNext sites.
babel - 1.1MB Gets imported because of dates, localization
sentry - 2.8MB should be loaded only if envvar is set
gettext - required for reading translations
2024-05-18 07:20:41 +00:00
Ankush Menat
7fe9cc4f09
perf: Don't update session in cache after every request (#26308)
It's just reading and writing same information except last_update inside
data which is never read back from this.
2024-05-04 06:10:38 +00:00
Ankush Menat
acf398f46e
fix: commit regardless of framework's transaction_writes count (#25322)
- There is code that depends on "commit", everything that happens with `db.after_commit`.
- There are operations that will not write anything to DB but just
  enqueue the function, if it's enqueue_after_commit then it will break.
2024-03-11 15:18:38 +05:30
Ankush Menat
bb7c3c289c
feat: support array request type (#25109)
There can be external APIs like webhooks that only send array request,
in which case Frappe has no mechanism to accept such requests.

After this PR such request data can be accessed using `data` list
argument on function.

I've considered directly storing list in form_dict but it's not
feasible:
1. It breaks semantics, "form_dict" can't be a list. That ship has long
   sailed.
2. Way too much code expects form_dict to be a dict.
2024-02-27 16:41:33 +00:00
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
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Akhil Narang
067104ca9c
refactor(sentry): sync up with FC implementation
Co-authored-by: Aditya Hase <aditya@adityahase.com>
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2023-12-26 12:30:10 +05:30
Ankush Menat
52686f79cb refactor: code cleanup
- better boot config name
- send sentry after - because frappe namespce doesn't exist if it starts
  first
- remove import in app.py because __init__ is always imported so no
  need.
- leave telemetry JS always present, this is used even when telemetry is
  not enabled.
2023-11-30 17:40:53 +05:30
Akhil Narang
9a0a5468c5 feat: setup sentry integration
Inspired primarily from sentry's generic WSGI integration

Environment variable `FRAPPE_SENTRY_DSN` needs to be enabled as well
as explicit opt-in from the user's side in system sid telemetry
settings

Conditionally include telemetry JS bundles

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2023-11-30 17:13:41 +05:30
Ankush Menat
28d05c41c3 fix: correct max file size in boot 2023-11-22 10:55:52 +05:30
Maharshi Patel
5af9b294f5 fix: honour max file size in upload file
In case path is /api/method/upload_file, we should honour the max file size
set in system settings and set request max_content_length to that value.
2023-11-21 16:36:57 +05:30
Ankush Menat
284649d4f2 fix: Use werkzeug to identify JSON requests
We were excluding flavoured JSON like `application/vnd.xxx+json` which
can be parsed as JSON.
2023-11-07 17:28:33 +05:30
Ankush Menat
507343f4f6 fix: double response processing 2023-10-16 18:12:53 +05:30
Ankush Menat
e0f87dc4e1 refactor!: move OAuth and token auth code to auth.py
This doesn't belong in api.py
2023-10-16 18:12:53 +05:30
Ankush Menat
5af6624cce refactor: Use werkzeug router for API routing 2023-10-16 18:12:53 +05:30
Ankush Menat
c7338f5a83 chore: deprecate form_dict.cmd, globals() 2023-10-16 18:12:53 +05:30
barredterra
ed2290d1d6 Merge branch 'develop' into feat/improve-openid-connect-devx 2023-10-07 15:22:59 +02:00