Skip to content

Conversation

@Dieterbe
Copy link
Contributor

@Dieterbe Dieterbe commented Aug 2, 2024

No description provided.

This is needed since the move to vite on the react side
This wasn't working well with when used over the API
This still needs to be clean up (specially the key generation, at the moment we
use a new dependency, but all this can be also done with the library we currently
use)
try:
return JsonResponse({'token': token, 'powersync_url': settings.POWERSYNC_URL}, status=200)
except Exception as e:
return JsonResponse({'error': str(e)}, status=500)

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 4 months ago

To resolve this, alter the API error response to send a generic message to the consumer instead of the detailed exception message. Internally, log the full exception for debugging and traceability. Specifically, in get_powersync_token in wger/core/api/views.py, replace:

return JsonResponse({'error': str(e)}, status=500)

with:

logging.exception("Error creating PowerSync token")
return JsonResponse({'error': 'An internal error has occurred.'}, status=500)

This change ensures that the exception detail is captured in server logs for developers and support staff, while API clients cannot see implementation details. Add the use of logging for exceptions in this block only; logging is already imported in the module (line 20).

Suggested changeset 1
wger/core/api/views.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/wger/core/api/views.py b/wger/core/api/views.py
--- a/wger/core/api/views.py
+++ b/wger/core/api/views.py
@@ -473,7 +473,8 @@
     try:
         return JsonResponse({'token': token, 'powersync_url': settings.POWERSYNC_URL}, status=200)
     except Exception as e:
-        return JsonResponse({'error': str(e)}, status=500)
+        logging.exception("Error creating PowerSync token")
+        return JsonResponse({'error': 'An internal error has occurred.'}, status=500)
 
 
 @api_view()
EOF
@@ -473,7 +473,8 @@
try:
return JsonResponse({'token': token, 'powersync_url': settings.POWERSYNC_URL}, status=200)
except Exception as e:
return JsonResponse({'error': str(e)}, status=500)
logging.exception("Error creating PowerSync token")
return JsonResponse({'error': 'An internal error has occurred.'}, status=500)


@api_view()
Copilot is powered by AI and may make mistakes. Always verify output.
rolandgeider and others added 12 commits September 8, 2024 21:04
most convenient and should be just fine
This is only needed because powersync can't handle joins
- move create publication to core
- use ivm entries for the nutrition publications
# Conflicts:
#	wger/core/static/react/main.js
This is needed in the flutter app to properly be able to set IDs on device, since
the regular IDs can only be set by postgres.
# Conflicts:
#	extras/docker/development/Dockerfile
#	extras/docker/production/settings.py
#	requirements.txt
#	wger/core/api/views.py
#	wger/nutrition/models/plan.py
#	wger/urls.py
@real-yfprojects
Copy link

Hey there. What is the current state of this, which steps are needed going forward and how can I help (as a python dev)?

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