Zum Hauptinhalt springen
LIVE
CVSS 7.0CVE-2026-138158 | libgphoto2 through 2.5.34 contains a stack buffer overflow in sierra_get_string_register() that lets a malicious sierra-protocol camera or USB device overwrite stack memory. When files are listed, the device can answer the file-name register with an oversized packet, writing up to 32 KB past small stack buffers to cause crashes or possible code execution.CVSS 7.7CVE-2026-138159 | edbrowse through 3.8.19 contains an integer overflow in stringAndBytes() that allows malicious servers to write past a heap buffer by sending response bodies larger than 2 GB. When a user browses to an attacker-controlled HTTP, FTP, or gopher server, the oversized body skips reallocation and corrupts the heap, causing crashes or potentially code execution.CVSS 8.5CVE-2026-138160 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ReadBackupTextLen() that allows attackers to overwrite stack memory via crafted backup files. Attackers can supply overlong quoted text values decoded into a 10,000-byte stack array during convertbackup, restore, or GSM_ReadBackupFile calls, causing crashes or potential code execution.CVSS 8.5CVE-2026-138161 | Gammu before 1.45.2 contains a buffer overflow vulnerability in LoadBackup() that allows attackers to corrupt memory by supplying an overlong MD5 value in a crafted backup file. Attackers can overwrite adjacent phonebook and calendar entry pointers via strcpy() into MD5Original when files are loaded with convertbackup or restore, causing crashes or potential code execution.CVSS 7.3CVE-2026-138162 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in ALCATEL_EncodeString() that allows attackers to overwrite stack memory via oversized encoded phonebook text. Attackers can supply a crafted backup restored with gammu restore or addnew to an attached Alcatel phone, using GSM extension characters to crash Gammu or potentially execute code.CVSS 8.5CVE-2026-138163 | Gammu before 1.45.2 contains a heap-based buffer overflow in ReadWAPSettingsEntry() that allows attackers to corrupt heap memory via crafted backup files with excess WAP or MMS settings entries. Attackers can supply a backup with more than four TitleNN keys in a [WAPSettings] or [MMSSettings] section, loaded via convertbackup, restore, or GSM_ReadBackupFile, causing crashes or potential code execution.CVSS 4.8CVE-2026-138164 | Gammu before 1.45.2 contains a stack-based buffer overflow vulnerability in SaveBackupText() in backtext.c that allows attackers to corrupt stack memory by supplying long text fields. Attackers can craft a backup with long calendar or note fields that, when converted with gammu convertbackup, writes hex digits past the 10,000-byte stack buffer.CVSS 9.3CVE-2026-138154 | POSTAL 2 before build 26810491 contains a sandbox escape vulnerability that allows malicious Steam Workshop mods to execute code by calling ConsoleCommand with a start file URI. Attackers can ship a batch file in a mod at the predictable workshop install path and launch it via ShellExecuteW, executing commands as the player on Windows.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Adding Production-Safe API Logging to Django REST Framework

When a Django REST Framework API starts getting used in production, one of the first debugging problems is visibility. A user reports: “The API failed.” But fro…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 8 Min. Lesezeit
Quelle: dev.to
Rubrik: Secure Programming

When a Django REST Framework API starts getting used in production, one of the first debugging problems is visibility.



A user reports:




“The API failed.”




But from the backend side, we often need more context:




  • Which endpoint was called?

  • What was the HTTP method?

  • What status code was returned?

  • How long did the request take?

  • Was the request body valid?

  • Did the response fail because of validation, permissions, database latency, or something else?

  • Can we debug this without exposing passwords, tokens, or sensitive payloads?



Many teams solve this by writing custom middleware.



That works at first, but it can become risky over time.



Custom API logging often starts small:




print(request.body)
print(response.data)






Then it grows into:




  • storing logs in the database

  • masking sensitive values

  • handling large request/response bodies

  • tracking slow APIs

  • searching logs from Django admin

  • avoiding extra latency in the request path

  • supporting async deployments

  • adding request correlation or trace IDs

  • avoiding accidental logging of tokens, passwords, cookies, or API keys



At that point, API logging is no longer “just middleware”. It becomes part of production observability.



This is the problem I wanted to solve with DRF API Logger.



Disclosure: I maintain this open-source package. I am sharing it here because I think the problem is common in Django REST Framework projects, and I would also like feedback from other Django developers.






What DRF API Logger does



DRF API Logger is an open-source package for Django REST Framework projects that captures API request and response information.



It can log useful debugging information such as:




  • API URL

  • HTTP method

  • request headers

  • request body

  • response body

  • status code

  • client IP address

  • API execution time

  • optional request tracing information

  • slow API indicators

  • optional profiling information



The goal is not to replace every observability tool.



It is mainly useful when you want structured API-level logging inside a Django/DRF project without building and maintaining custom middleware from scratch.






Why not simply write custom middleware?



You can write your own middleware, and for small projects that may be enough.



But production API logging has some common traps.






1. Sensitive data exposure



This is the biggest issue.



Logging the full request body may accidentally store:




  • passwords

  • access tokens

  • refresh tokens

  • API keys

  • session IDs

  • cookies

  • authorization headers

  • personal user data



That makes logs dangerous.



Good API logging should support masking and exclusion rules from the beginning.



Example:




DRF_API_LOGGER_EXCLUDE_KEYS = [
"password",
"token",
"access",
"refresh",
"secret",
"api_key",
]






Even with masking, teams should still review what they log and decide what is acceptable for their own security, privacy, and compliance requirements.






2. Performance overhead



A simple custom logger may write to the database directly inside the request/response cycle.



That means every API request waits for logging work to finish.



For low traffic, this may be acceptable. For production traffic, this can add unnecessary latency.



A better pattern is to keep request-path work small and move heavier writes out of the main request flow where possible.






3. Large payloads



Some APIs return large JSON responses.



If logs store everything without limits, the logging table can grow quickly and become expensive to query.



A production logging setup should support body-size limits.



Example:




DRF_API_LOGGER_MAX_REQUEST_BODY_SIZE = 32768
DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = 65536









4. Search and debugging experience



Storing logs is only useful if developers can find the right records later.



For example:




  • show all 500 responses from the last hour

  • search by URL

  • filter by method

  • find slow APIs

  • inspect a specific failed request

  • compare status codes

  • check execution time



This is where Django admin visibility becomes useful for many teams.






Basic installation



Install the package:




pip install drf-api-logger






Add it to INSTALLED_APPS:




INSTALLED_APPS = [
# ...
"drf_api_logger",
]






Add the middleware:




MIDDLEWARE = [
# ...
"drf_api_logger.middleware.api_logger_middleware.APILoggerMiddleware",
]






Enable database logging:




DRF_API_LOGGER_DATABASE = True






Run migrations:




python manage.py migrate






After this, DRF API logs can be captured and viewed from Django admin.






A more production-aware configuration



For production-like environments, I would avoid enabling full logging blindly.



A safer starting point is:




DRF_API_LOGGER_DATABASE = True

DRF_API_LOGGER_EXCLUDE_KEYS = [
"password",
"token",
"access",
"refresh",
"secret",
"api_key",
"authorization",
"cookie",
"set-cookie",
]

DRF_API_LOGGER_MAX_REQUEST_BODY_SIZE = 32768
DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = 65536






This keeps the setup practical while reducing some common risks.



You should still review:




  • which endpoints should be logged

  • which fields should always be masked

  • how long logs should be retained

  • whether request/response bodies should be stored in your environment

  • whether logs contain personal or regulated data

  • whether logs should go to a separate database or storage backend






Using it for slow API investigation



One common use case is finding slow DRF endpoints.



For example, you may want to flag APIs slower than a specific threshold:




DRF_API_LOGGER_SLOW_API_ABOVE = 200






You can also enable profiling when you need deeper investigation:




DRF_API_LOGGER_ENABLE_PROFILING = True






This can help identify whether slowness is more likely coming from:




  • SQL queries

  • too many repeated queries

  • middleware overhead

  • view/business logic

  • serialization cost



This is useful when an endpoint “feels slow” but the team does not yet know where the time is going.






Database logging vs signal-based logging



Not every team wants to store API logs in the default database.



Some teams may want to send API log data somewhere else:




  • a file

  • an analytics pipeline

  • a monitoring system

  • a separate database

  • a queue

  • a custom internal tool



For that, signal-based logging can be useful.



Example:




DRF_API_LOGGER_SIGNAL = True






Then a listener can handle the log event:




from drf_api_logger import API_LOGGER_SIGNAL


def send_to_internal_observability_tool(**kwargs):
# Example only.
# Be careful not to export sensitive request/response bodies.
print({
"api": kwargs.get("api"),
"method": kwargs.get("method"),
"status_code": kwargs.get("status_code"),
"execution_time": kwargs.get("execution_time"),
})


API_LOGGER_SIGNAL.listen += send_to_internal_observability_tool






This gives more flexibility if the default database is not the right place for logs.






Security and privacy notes



API logs can be extremely helpful, but they can also become a liability.



Before enabling request/response logging in production, I recommend reviewing these questions:






1. Are we logging secrets?



Avoid storing:




  • passwords

  • tokens

  • API keys

  • cookies

  • session IDs

  • authorization headers






2. Are we logging personal data?



Depending on your application, request and response bodies may contain personal information.



Examples:




  • names

  • phone numbers

  • email addresses

  • addresses

  • payment-related information

  • health-related information

  • user documents



Do not treat API logs as harmless debugging data.






3. Do we need full bodies?



For many APIs, logging metadata is enough:




  • URL

  • method

  • status code

  • execution time

  • client IP

  • trace ID



Full request/response bodies should be enabled carefully.






4. What is the retention policy?



Logs should not live forever by default.



Teams should decide how long API logs are useful and when they should be deleted or archived.






5. Who can access the logs?



If logs are visible in Django admin, make sure admin access is properly restricted.



API logs may reveal internal system behavior and user data.






When I would use this package



I would consider using DRF API Logger when:




  • the project uses Django REST Framework

  • the team needs request/response visibility

  • developers are currently debugging production issues manually

  • custom middleware is growing too complex

  • slow API investigation is needed

  • Django admin visibility is useful

  • sensitive data masking and payload limits are required

  • the team wants a package instead of maintaining logging middleware internally






When I would not use it



I would not enable full API body logging blindly in every project.



I would be careful if:




  • the application handles highly sensitive data

  • compliance requirements are strict

  • the team does not have a retention policy

  • admin access is not well controlled

  • the database is already under heavy write load

  • only high-level metrics are needed



In those cases, metadata-only logging, signal-based logging, OpenTelemetry, APM tools, or custom policies may be more appropriate.






Minimal example



Here is a compact setup:




INSTALLED_APPS = [
# ...
"drf_api_logger",
]

MIDDLEWARE = [
# ...
"drf_api_logger.middleware.api_logger_middleware.APILoggerMiddleware",
]

DRF_API_LOGGER_DATABASE = True

DRF_API_LOGGER_EXCLUDE_KEYS = [
"password",
"token",
"access",
"refresh",
"secret",
"api_key",
]

DRF_API_LOGGER_MAX_REQUEST_BODY_SIZE = 32768
DRF_API_LOGGER_MAX_RESPONSE_BODY_SIZE = 65536

DRF_API_LOGGER_SLOW_API_ABOVE = 200






Then run:




python manage.py migrate













Feedback request



I would appreciate feedback from Django and DRF developers on a few areas:




  • What do you expect from API logging in production?

  • Do you prefer database logging, signals, OpenTelemetry, or another storage backend?

  • What masking rules should be enabled by default?

  • What would make the admin debugging experience more useful?

  • What concerns would stop you from using request/response logging?



I am especially interested in feedback around security, privacy, performance, and real production debugging workflows.



Thanks for reading.

Information ergänzen Fachhinweis, Update, Korrektur oder Quelle zur Meldung beitragen
Gäste-Hinweise werden kurz redaktionell geprüft und danach hier angezeigt.

Community-Hinweise zur Meldung

0 freigegeben
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!
Informations-Bewertung:

💬 Community discussion & comments

🌐 Join the main chat

Start the discussion in the Social Chat broadcast stream or submit an expert contribution via the supplement form above.

Community Rating & Social Proof
⭐ Reader Rating
–
Ø / 5.0
No reader ratings yet
Was this article helpful?
0
Submit your rating
Detailed rating (optional)
Content & Quality
Source & Credibility
Freshness
Security Briefing Free · 1-Click Unsubscribe

Intelligence Digest — free

The top security news daily · unsubscribe anytime

Related story clusters & sources (vector AI)

6 Cluster
22 sources
CVE-2026-72109 | Linux Kernel up to 7.1.4 sparx5 sparx5_register_notifier_blocks allocation of resources (WID-SEC-2026-2852)
VulDB Updates 1 hour ago
21 more sources
VulDB Updates1 hour agoCVE-2026-72110 | Linux Kernel up to 7.2-rc1 BPF bpf_local_storage_destroy use after free (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72111 | Linux Kernel up to 6.12.102/6.18.39/7.1.4 BPF Verifier check_mem_access memory corruption (Nessus ID 339550 / WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72112 | Linux Kernel up to 7.1.4/7.2-rc3 BPF Ops io_uring io_install_bpf priv/ring_fd use after free (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72113 | Linux Kernel up to 7.2-rc3 bcm bcm.c bcm_release/bcm_delete_rx_op/bcm_notifier rx_reg_dev use after free (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72114 | Linux Kernel up to 7.2-rc3 bcm bcm_rx_setup len buffer overflow (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72115 | Linux Kernel up to 7.2-rc3 bcm bcm_rx_handler race condition (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72116 | Linux Kernel up to 7.2-rc3 bcm bcm_rx_setup race condition (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72117 | Linux Kernel up to 7.2-rc3 bcm bcm_rx_handler locking (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72118 | Linux Kernel up to 7.2-rc3 bcm bcm_rx_handler race condition (WID-SEC-2026-2852) VulDB Updates1 hour agoCVE-2026-72119 | Linux Kernel up to 7.2-rc3 bcm net/can/bcm.c bcm_tx_setup race condition (WID-SEC-2026-2852) DEV Community3 hours agoKnuth's moratorium on error reports: what his page says, why repeats cost time, and what curl and the Linux kernel did VulDB Updates3 hours agoCVE-2026-72099 | Linux Kernel up to 7.2-rc2 dm-integrity infinite loop (Nessus ID 364704 / WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72100 | Linux Kernel up to 6.12.96/6.18.39/7.1.4/7.2-rc2 dm-integrity deadlock (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72101 | Linux Kernel up to 6.12.100/6.18.39/7.1.4/7.2-rc2 dm-integrity uninitialized pointer (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72103 | Linux Kernel up to 6.12.100/6.18.41/7.1.4/7.2-rc2 dm-crypt crypt_set_keyring_key information disclosure (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72102 | Linux Kernel up to 7.2-rc2 Device Mapper dm_early_create use after free (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72104 | Linux Kernel up to 6.18.39/7.1.4/7.2-rc2 dm-pcache parse_cache_opts null pointer dereference (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72105 | Linux Kernel up to 7.2-rc2 dm-log out-of-bounds write (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72107 | Linux Kernel up to 7.2-rc2 dm era writeset_marked out-of-bounds (WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72106 | Linux Kernel up to 7.2-rc2 dm-ioctl list_version_get_info buffer overflow (Nessus ID 335743 / WID-SEC-2026-2852) VulDB Updates3 hours agoCVE-2026-72108 | Linux Kernel up to 7.2-rc2 dm thin metadata __reserve_metadata_snap/__release_metadata_snap reference count (WID-SEC-2026-2852)
20 sources
'King-sized' Black Friday deal: Save 79% off Paramount+
Latest from TechRadar 31 min. ago
19 more sources
Latest from TechRadar21 min. agoBig features, tiny price tags: The 4 best-value VPN deals of Black Friday 2026 Latest from Windows Central1 hour agoThe best Xbox and PC Black Friday deals you need to know about without the fluff WIRED2 hours agoHexClad Pans Black Friday Sale: Save Up to $70 (2026) WIRED2 hours agoOura Ring 5 Is $100 Off This Black Friday and Cyber Week (2026) Latest from TechRadar3 hours agoI tried 20+ Android TV VPNs this year and these are the ones I’d save on this Black Friday — VPNs for beginners, 4K streaming, and good savings CNET3 hours agoI Love This Fender Speaker for Its Looks and Its Bass, and It’s Still $45 Off After Black Friday WIRED3 hours agoAir Purifier Black Friday Sale: Levoit, Blueair (2026) Latest from TechRadar3 hours agoBlack Friday MacBook deals 2026: even bigger savings on MacBook Neo, MacBook Pro M6, and the new PROLED MacBook Pros as Cyber Monday draws near WIRED3 hours agoThe Best Black Friday MacBook Deals Take Up to $300 Off The Verge3 hours agoA tech girlie’s Black Friday guide to fabulous nails WIRED3 hours agoThe Best Black Friday Action Camera Deals (2026) Latest from Windows Central3 hours agoBought a new PC or monitor on Black Friday? Don't plug it into a cheap power strip Latest from TechRadar3 hours agoHere’s the best Black Friday MacBook Air deal available right now Latest from TechRadar4 hours agoI've reviewed a whole host of docking stations — here are the 8 worth buying in the holiday deals now Black Friday is done Latest from TechRadar4 hours agoFastestVPN vs PrivadoVPN vs Windscribe: which cheap VPN should you buy this Black Friday? Latest from TechRadar4 hours agoWalmart's Black Friday event ends tomorrow — see the 20 best last chance deals on TVs, appliances, laptops, headphones, ahead of Cyber Monday WIRED4 hours agoBest JBL Black Friday Deals (2026): Save on JBL Flip 7 and More The Verge4 hours agoBirdbuddy’s latest smart feeders are still at their low Black Friday prices WIRED4 hours agoBest Black Friday Meal Kit Deals: CookUnity, Green Chef, & More
Similar posts
🔍 Verwandte News

Auch interessante Nachrichten Adding Production-Safe API Logging to Django REST Framework

Thematisch verwandte Begriffe: Adding, ProductionSafe, Logging, Django · 6 Treffer

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

💬 Loading comments…
Pull to refresh
Widgets & Topics
Loading widgets…
Nächster Beitrag