Commit Graph

46 Commits

Author SHA1 Message Date
Feanil Patel
455033458c feat!: Replace logging WaffleSwitch with a django settinge.
This was initially introduced as a temporary flag to be able to get more
information.  But if we get this kind of issue again, we'll need
something like this logging to determine the source of the session
collision.  Rather than removing the code and adding it back in later,
convert this temporary switch into an opt-in setting that can be used
again in the future.

BREAKING_CHANGE: 'safe_session.log_request_user_changes' switch no
longer exists and is replaced with the 'LOG_REQUEST_USER_CHANGES' django
setting which defaults to 'False'
2021-04-02 14:20:07 -04:00
Feanil Patel
23f2b758d4 fix: Print more stack frames on requset tracing.
Six frames was not enough because for DRF views the request gets wrapped
in a proxy object and so we need more of the stack to see what part of
the code we're in that actually invokes the use change.
2021-04-02 14:19:07 -04:00
Feanil Patel
5b7caf45d6 fix: Don't log warnings on logout.
When a user logs out, there are warnings logged right now because the
session user_id mismatches(it becomes None on logout).  Previously we
would log the request mismatch on debug and the session mismatch as
normal.

This change will result in us logging nothing if the session change is
not abnormal.
2021-04-01 16:42:21 -04:00
Feanil Patel
c1bdf01876 fix: Don't make request change logging a waffle flag.
Waffle flags are useful for gradual rollout but that's not possible this
high in the middleware because a lot of the data needed (request.user)
to partition incoming requests is not availabale this high in the
middleware.

Convert this to a WaffleSwitch which will be safer to operate.

Also increase the number of frames in the stack to print per change.
Printing just 1 did not provide enough info because DRF requests wrap
WSGI requests and have a setter proxy.  It will be useful to figure out
how they do this in case it's better that what we're doing in the safe
sessions middleware.

Ticket: https://openedx.atlassian.net/browse/ARCHBOM-1718
2021-03-26 14:38:35 -04:00
Feanil Patel
0714ac5f0e feat: Add more detailed request user change logging.
The change is behind a WafleFlag and can be turned on to log every time
the `user` attribute of an instrumented request changes.  This will
significantly increase log volume so it shouldn't be left on all the
time but can be turned on to quickly debug issues related to sessions.

Ticket: https://openedx.atlassian.net/browse/ARCHBOM-1718
2021-03-25 12:14:53 -04:00
Feanil Patel
c67c401f89 temp: remove false positives on safe sessions middleware (#27105)
* temp: remove false positives on safe sessions middleware

This is a temporary fix to deal with false positives in the system due
to the masquerading feature.  Long term we may not want to rely on
knowing about how masquerding works in the safe sessions middleware and
instead manage masquerding of the requset user in some other way.

Co-authored-by: Robert Raposa <rraposa@edx.org>
2021-03-22 14:44:52 -04:00
M. Zulqarnain
91d33611b1 refactor: pyupgrade in profile_images, programs, safe_sessions (#26953) 2021-03-22 17:51:13 +05:00
Feanil Patel
416407fd73 fix: Add more info in warning log messages.
If this happens, it's usefule to know what main view code was being
targetd so that we can more easily investigate what might have caused
this issue.

Add a new custom attribute 'safe_sessions.user_mismatch' to find
requests that had this issue in our monitoring system.
2021-03-18 11:33:08 -04:00
Aarif
cfcb9330b3 replaced unittest assertions pytest assertions (#26568) 2021-02-22 12:24:33 +05:00
usamasadiq
e6d43ac69c Applied pylint amnesty 2021-02-08 12:45:57 +05:00
Kyle McCormick
151bd13666 Use full names for common.djangoapps imports; warn when using old style (#25477)
* Generate common/djangoapps import shims for LMS
* Generate common/djangoapps import shims for Studio
* Stop appending project root to sys.path
* Stop appending common/djangoapps to sys.path
* Import from common.djangoapps.course_action_state instead of course_action_state
* Import from common.djangoapps.course_modes instead of course_modes
* Import from common.djangoapps.database_fixups instead of database_fixups
* Import from common.djangoapps.edxmako instead of edxmako
* Import from common.djangoapps.entitlements instead of entitlements
* Import from common.djangoapps.pipline_mako instead of pipeline_mako
* Import from common.djangoapps.static_replace instead of static_replace
* Import from common.djangoapps.student instead of student
* Import from common.djangoapps.terrain instead of terrain
* Import from common.djangoapps.third_party_auth instead of third_party_auth
* Import from common.djangoapps.track instead of track
* Import from common.djangoapps.util instead of util
* Import from common.djangoapps.xblock_django instead of xblock_django
* Add empty common/djangoapps/__init__.py to fix pytest collection
* Fix pylint formatting violations
* Exclude import_shims/ directory tree from linting
2020-11-10 07:02:01 -05:00
Michael Terry
c2033f9667 Small PLS courseware banner fixes
- Hide the submit-button CTA link to reset dates in the mobile
  app. They are working on their own solution.
- Don't show the dates_banner.html code in the courseware. It has
  new CTA banner support with updated wording.
2020-08-10 09:44:43 -04:00
Ayub-khan
d3a02bc3e5 BOM-1121
-Updated middleware setting to use use middleware insted of
middleware_classes
-github install of django-method-override fork to support
new style middleware in django1.11
2020-02-11 14:35:26 +05:00
Aarif
97d327feeb BOM-1121
Old style mixin compatibility with django2.2
2020-01-30 16:36:02 +05:00
Feanil Patel
046feb0cf0 Merge pull request #22649 from edx/feanil/fix_pep8
Fix all E303 pep8 errors.
2019-12-30 13:32:26 -05:00
Feanil Patel
6e3fe00fff Fix all E303 pep8 errors. 2019-12-30 12:25:38 -05:00
Feanil Patel
2df8b8226b Merge pull request #22643 from edx/feanil/2to3_asserts
Run `2to3 -f asserts . -w` on edx-platform.
2019-12-30 12:13:42 -05:00
Feanil Patel
9cf2f9f298 Run 2to3 -f future . -w
This will remove imports from __future__ that are no longer needed.

https://docs.python.org/3.5/library/2to3.html#2to3fixer-future
2019-12-30 10:35:30 -05:00
Feanil Patel
70294b0ad2 Run 2to3 -f asserts . -w on edx-platform.
https://docs.python.org/3.5/library/2to3.html#2to3fixer-asserts
2019-12-30 10:22:19 -05:00
Feanil Patel
6e6c489f1f Merge pull request #21372 from edx/feanil/fix_cmp_issues
Fix a few issues we run into when running tests in python 3.
2019-08-20 11:28:23 -04:00
Feanil Patel
1367b0cf3d Move the unicode_compatible decorator to the class. 2019-08-19 11:00:25 -04:00
Dave St.Germain
5febcce20c Fix python3 compatibility in SafeCookieData and elsewhere 2019-08-19 10:24:15 -04:00
Ayub khan
ea0c6922fe BOM-87
Fixed the test for py3.
2019-08-19 18:52:19 +05:00
Feanil Patel
c2d76a6072 More python 3 fixes in the safe_sessions middleware. 2019-08-17 23:03:41 -04:00
Ayub
98fa0b7b3e py3 bug fix (#21351) 2019-08-16 14:48:01 -04:00
Mayank Jain
9bffa9a914 INCR-219: Run modernizer (#20415)
* INCR-219: Run python-modernize on `openedx/core/djangoapps/safe_sessions`

* disable pylint on six import to avoid isort and pylint guideline conflict
2019-05-07 16:41:53 -04:00
Ned Batchelder
7d964b12db Context managers need to clean up properly
An @contextmanager will raise an exception from its yield statement if
an exception happens in the with-block that uses it.  If the context
manager needs to do clean up, it should do it even if an exception is
raised, so it needs to be done in a finally clause.
2019-04-17 13:14:48 -04:00
David Ormsbee
40e1e1e59e Improve SafeCookieData Error Logging
1. Use request.session instead of request.user, since request.user
won't necessarily be properly set.

2. Be extra paranoid by putting logging after session cookie deletion,
so that even if there is some error related to logging, the important
work will complete and the browser won't get left in a broken state.

3. Write out the full contents of the Cookie header (up to 4096 bytes)
in the log as a base64 encoded string. This way we can look at broken
cookie states and diagnose what's breaking them (the Python parser will
just silently skip anything past a corrupted cookie entry). We base64
encode mostly to prevent people from maliciously injecting garbage into
our logs.
2019-02-24 13:57:19 -05:00
David Ormsbee
fc52fcccab Log when SafeSessionMiddleware deletes cookies 2019-02-22 17:12:18 -05:00
Matthew Piatetsky
f294b1a374 fix unicode strings in openedx/ part 1 2019-02-13 10:47:35 -05:00
Michael Youngstrom
4bbd1dee0b Remove shards from commonlib-unit tests 2019-02-12 14:28:35 -05:00
Ned Batchelder
59d78031d8 Fix trailing-comma-tuple warnings 2018-11-02 11:06:59 -04:00
Michael Youngstrom
8aed0ff719 Clean up after any get_mock_request or set_current_request calls 2018-08-22 17:23:39 -04:00
Jeremy Bowman
380a24f7ef TE-2689 Remove useless pylint suppressions part 6 2018-08-21 13:54:34 -04:00
Jeremy Bowman
c290bf8a07 TE-2524 Stop using nose.plugins - openedx 2018-08-02 14:54:50 -04:00
Jeremy Bowman
5289c7e828 PLAT-1915 Stop using deprecated BaseException.message 2018-01-31 17:22:01 -05:00
Ned Batchelder
e23e3a0486 Fix a number of unused-import pylint violations 2017-11-21 19:57:06 -05:00
John Eskew
947e814216 Remove deprecated django.utils.importlib. 2017-06-29 12:08:21 -04:00
Andy Armstrong
93235d118d Reorder imports using isort (except lms and cms) 2017-05-30 16:04:54 -04:00
J. Cliff Dyer
9366c43a83 Fix issues with RequestFactory used as Request.
* Centralize creation of quick request objects.
* Isolate caches to individual tests to prevent test ordering
  dependencies.

TNL-5811
2016-11-07 10:51:04 -05:00
Calen Pennington
bc20a37c2b Simplify how shards are selected in CI 2016-08-03 16:23:02 -04:00
Ben Patterson
c504029b39 Create a third shard for lms unit tests.
This will leverage the nose attrib plugin to allow us
to break tests apart on our build system to run
in parallel on separate nodes.
2016-03-17 12:01:42 -04:00
Nimisha Asthagiri
de3fca35be Quiet the safe sessions logging for expected use case 2016-03-02 14:47:44 -05:00
Qubad786
faf3a64e36 Bypass unnecessary logs on loging out 2016-02-17 13:42:01 +05:00
Nimisha Asthagiri
e76e05fa77 Specially handle login redirect for mobile apps 2016-01-26 17:23:04 -05:00
Nimisha Asthagiri
f3cb692472 Safe Session Cookies Middleware 2016-01-26 17:23:03 -05:00