Merge pull request #582 from micropyramid-dev/security/fix-codeql-info-exposure
security: stop leaking exception details in API responses
This commit is contained in:
commit
e6995e3f56
3 changed files with 39 additions and 20 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import logging
|
||||
import secrets
|
||||
|
||||
import requests
|
||||
|
|
@ -16,6 +17,8 @@ from rest_framework_simplejwt.tokens import RefreshToken
|
|||
|
||||
from common import serializer
|
||||
from common.models import Org, Profile, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from common.serializer import OrgAwareRefreshToken
|
||||
|
||||
|
||||
|
|
@ -192,9 +195,10 @@ class GoogleIdTokenView(APIView):
|
|||
)
|
||||
email = idinfo.get("email")
|
||||
picture = idinfo.get("picture", "")
|
||||
except ValueError as e:
|
||||
except ValueError:
|
||||
logger.warning("Google OAuth token validation failed", exc_info=True)
|
||||
return Response(
|
||||
{"error": f"Invalid token: {str(e)}"},
|
||||
{"error": "Invalid token"},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import logging
|
||||
from decimal import Decimal
|
||||
|
||||
from django.conf import settings
|
||||
|
|
@ -14,6 +15,8 @@ from rest_framework.permissions import IsAuthenticated
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from common.models import Attachments, Comment
|
||||
from common.permissions import HasOrgContext
|
||||
from common.serializer import AttachmentsSerializer, CommentSerializer
|
||||
|
|
@ -561,14 +564,16 @@ class InvoicePDFView(APIView):
|
|||
response = HttpResponse(pdf_content, content_type="application/pdf")
|
||||
response["Content-Disposition"] = f'attachment; filename="{filename}"'
|
||||
return response
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
logger.exception("PDF generation library not available")
|
||||
return Response(
|
||||
{"error": True, "message": str(e)},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
{"error": True, "message": "PDF generation unavailable"},
|
||||
status=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception("Failed to generate invoice PDF")
|
||||
return Response(
|
||||
{"error": True, "message": f"Error generating PDF: {str(e)}"},
|
||||
{"error": True, "message": "Failed to generate PDF"},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
|
@ -1197,14 +1202,16 @@ class EstimatePDFView(APIView):
|
|||
response = HttpResponse(pdf_content, content_type="application/pdf")
|
||||
response["Content-Disposition"] = f'attachment; filename="{filename}"'
|
||||
return response
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
logger.exception("PDF generation library not available")
|
||||
return Response(
|
||||
{"error": True, "message": str(e)},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
{"error": True, "message": "PDF generation unavailable"},
|
||||
status=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception("Failed to generate estimate PDF")
|
||||
return Response(
|
||||
{"error": True, "message": f"Error generating PDF: {str(e)}"},
|
||||
{"error": True, "message": "Failed to generate PDF"},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,16 @@ Public views for client portal.
|
|||
These views do not require authentication and are accessed via public tokens.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.utils import timezone
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from invoices.models import Invoice, Estimate, InvoiceTemplate
|
||||
from invoices.pdf import (
|
||||
generate_invoice_pdf,
|
||||
|
|
@ -147,14 +151,16 @@ class PublicInvoicePDFView(APIView):
|
|||
response = HttpResponse(pdf_content, content_type="application/pdf")
|
||||
response["Content-Disposition"] = f'attachment; filename="{filename}"'
|
||||
return response
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
logger.exception("PDF generation library not available")
|
||||
return Response(
|
||||
{"error": True, "message": f"PDF generation unavailable: {str(e)}"},
|
||||
{"error": True, "message": "PDF generation unavailable"},
|
||||
status=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception("Failed to generate invoice PDF")
|
||||
return Response(
|
||||
{"error": True, "message": f"Failed to generate PDF: {str(e)}"},
|
||||
{"error": True, "message": "Failed to generate PDF"},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
|
@ -278,14 +284,16 @@ class PublicEstimatePDFView(APIView):
|
|||
response = HttpResponse(pdf_content, content_type="application/pdf")
|
||||
response["Content-Disposition"] = f'attachment; filename="{filename}"'
|
||||
return response
|
||||
except ImportError as e:
|
||||
except ImportError:
|
||||
logger.exception("PDF generation library not available")
|
||||
return Response(
|
||||
{"error": True, "message": f"PDF generation unavailable: {str(e)}"},
|
||||
{"error": True, "message": "PDF generation unavailable"},
|
||||
status=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
logger.exception("Failed to generate estimate PDF")
|
||||
return Response(
|
||||
{"error": True, "message": f"Failed to generate PDF: {str(e)}"},
|
||||
{"error": True, "message": "Failed to generate PDF"},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue