Zum Hauptinhalt springen
LIVE
CVSS 6.9CVE-2026-137684 | A security flaw has been discovered in eosphoros-ai DB-GPT up to 0.8.3. This affects the function editor_sql_run of the file packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/editor/api_editor_v1.py of the component Editor SQL Run API. Performing a manipulation of the argument db_name results in authorization bypass. It is possible to initiate the attack remotely. The exploit has been released to the public and may be used for attacks. The pull request to fixCVSS 8.7CVE-2026-137992 | libexpat through 2.11.0 contains a denial of service vulnerability in defineAttribute() of lib/xmlparse.c that fails to detect duplicate non-ID #IMPLIED or #REQUIRED attribute declarations. Attackers can supply a crafted XML document with repeated ATTLIST declarations in an internal DTD subset to cause quadratic CPU consumption in storeAtts() during parsing.CVSS 8.5CVE-2026-137994 | Leo through 6.8.10 contains an insecure deserialization vulnerability that allows attackers to execute code by embedding pickled data in unknown XML attributes of .leo outlines. Attackers can place a pickle __reduce__ gadget in a or element attribute that resolveUa passes to pickle.loads, executing code with user privileges when the outline is opened.CVSS 7.0CVE-2026-137995 | FOG Project before 1.6.0.119 contains an information disclosure vulnerability that allows unauthenticated attackers to obtain host tokens from status/hostgetkey.php by supplying a host MAC address. Attackers can present the token to service/hostinfo.php to retrieve decrypted Active Directory join credentials and Windows product keys during deployment windows.CVSS 6.8CVE-2026-137996 | Zettlr before 4.11.0 fails to validate URI schemes in Markdown link targets, allowing attackers to launch arbitrary registered protocol handlers via Electron shell.openExternal without confirmation. Attackers can craft documents whose Ctrl/Cmd-clicked links use smb:// to leak NTLM credential hashes on Windows or invoke custom protocol handlers with attacker-controlled parameters.CVSS 8.5CVE-2026-137997 | HCIPy through 0.7.1 contains an insecure deserialization vulnerability that allows attackers to execute code by supplying crafted .pkl files to read_field, read_grid or read_mode_basis. Because hcipy/util/io.py selects pickle by file extension and calls pickle.load, a __reduce__ gadget in a pupil, apodizer, PSF or mode-basis file runs code with the user's privileges.CVSS 8.5CVE-2026-137998 | Detoxify 0.5.3 through 0.5.4 contains an insecure deserialization vulnerability in load_checkpoint that allows attackers to execute code by supplying a crafted checkpoint file. Attackers can embed a pickle __reduce__ gadget in a .ckpt file loaded via torch.load with weights_only=False to run code with the user's privileges.CVSS 8.5CVE-2026-137999 | JSONSchema2PoPo2 through 3.0.3 contains a code injection vulnerability that allows attackers to inject Python code by supplying JSON Schema default or format values that are written unescaped. Attackers can place a single quote in a string property default to break out of the literal in the generated __init__ signature, executing injected code when the generated module is imported.
Alle im Drawer
Intelligence View
⚡ tsecurity.de Intelligence

Refactoring Legacy Code: A Jedi’s Guide to Clean Code

The Quest Begins (The "Why") I still remember the first time I opened a legacy service that had been untouched for three years. The file was a monolithic…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Quelle & Fakten · 5 Min. Lesezeit
Quelle: dev.to
Rubrik: Sichere Programmierung




The Quest Begins (The "Why")



I still remember the first time I opened a legacy service that had been untouched for three years. The file was a monolithic 2,000‑line beast, littered with numbers like 42, 0xFF, and 3.14159 scattered everywhere. I spent an afternoon tracing a bug only to discover that someone had changed the timeout value in one place but missed the other three copies. The feeling? Like trying to defeat a boss in Dark Souls without ever learning its attack pattern—frustrating, endless, and you keep dying for the same stupid reason.



That experience taught me a hard truth: magic numbers are silent saboteurs. They make code hard to read, harder to test, and almost impossible to change safely. If you’ve ever felt like you’re reading ancient runes instead of plain English, you know exactly what I mean.






The Revelation (The Insight)



The breakthrough came when I stumbled upon a simple, yet powerful rule: replace every literal value that isn’t self‑explanatory with a named constant. It sounds trivial, but the impact is massive. By giving intention to those numbers, the code starts to tell a story instead of hiding it.



Why does this work?





  • Readability – A name like MAX_RETRY_ATTEMPTS instantly conveys purpose; a bare 3 leaves you guessing.


  • Safety – Change the value in one place, and every usage updates automatically. No more “did I miss one?” panic.


  • Testability – Constants can be overridden in test stubs or config files without digging through logic.


  • Documentation – The constant itself becomes a piece of documentation that lives right next to the code that uses it.



In short, naming your literals turns a cryptic spell into a clear incantation.






Wielding the Power (Code & Examples)



Let’s look at a real‑world snippet I inherited—a function that processed user uploads.






Before: The Chaos






def handle_upload(file):
if file.size > 10 * 1024 * 1024: # 10 MB limit
raise ValueError("File too large")

if file.type not in ['image/jpeg', 'image/png', 'image/gif']:
raise ValueError("Unsupported file type")

if file.name.endswith('.tmp'):
# skip temporary files
return None

# generate a thumbnail
thumb = create_thumbnail(file, width=128, height=128)

# store metadata
meta = {
'owner': file.owner_id,
'uploaded_at': datetime.utcnow(),
'size': file.size,
'type': file.type,
'checksum': compute_md5(file)
}

# retry logic for flaky storage
for attempt in range(3):
try:
save_to_storage(file, meta)
break
except StorageError:
if attempt == 2:
raise
time.sleep(0.5 * (2 ** attempt)) # exponential backoff

return thumb






See the problems?





  • 10 * 1024 * 1024 – what’s that? A comment helps, but the comment can drift.

  • The list ['image/jpeg', 'image/png', 'image/gif'] appears nowhere else; if we add a format we have to hunt it down.

  • Hard‑coded 128 for thumbnail dimensions—what if the UI changes?

  • The retry loop uses 3 and 0.5 * (2 ** attempt)—magic numbers that hide the intent (max attempts, base delay, backoff factor).



A small change in one place could easily be missed, leading to oversized uploads slipping through or thumbnails being the wrong size.






After: The Clarity






# constants.py
MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024 # 10 MB
ALLOWED_MIME_TYPES = {'image/jpeg', 'image/png', 'image/gif'}
THUMBNAIL_WIDTH = 128
THUMBNAIL_HEIGHT = 128
MAX_UPLOAD_ATTEMPTS = 3
BASE_RETRY_DELAY_SECONDS = 0.5
BACKOFF_FACTOR = 2

# upload_handler.py
from .constants import (
MAX_FILE_SIZE_BYTES,
ALLOWED_MIME_TYPES,
THUMBNAIL_WIDTH,
THUMBNAIL_HEIGHT,
MAX_UPLOAD_ATTEMPTS,
BASE_RETRY_DELAY_SECONDS,
BACKOFF_FACTOR,
)

def handle_upload(file):
if file.size > MAX_FILE_SIZE_BYTES:
raise ValueError("File too large")

if file.type not in ALLOWED_MIME_TYPES:
raise ValueError("Unsupported file type")

if file.name.endswith('.tmp'):
return None

thumb = create_thumbnail(file, width=THUMBNAIL_HEIGHT, height=THUMBNAIL_WIDTH)

meta = {
'owner': file.owner_id,
'uploaded_at': datetime.utcnow(),
'size': file.size,
'type': file.type,
'checksum': compute_md5(file)
}

for attempt in range(MAX_UPLOAD_ATTEMPTS):
try:
save_to_storage(file, meta)
break
except StorageError:
if attempt == MAX_UPLOAD_ATTEMPTS - 1:
raise
time.sleep(BASE_RETRY_DELAY_SECONDS * (BACKOFF_FACTOR ** attempt))

return thumb






What changed?




  • Every numeric literal now has a name that explains why it exists.

  • The set of allowed MIME types is a constant—adding a new format is a single line edit.

  • Thumbnail dimensions are grouped; if the design team wants 150 px, we adjust two constants.

  • The retry policy is self‑documenting: “we try three times, starting with half a second and doubling each wait.”



The function is now a straightforward narrative. If a bug appears, I can point to the exact constant that’s suspect, rather than hunting through arithmetic expressions.






Why This New Power Matters



Adopting the “name your literals” habit reshapes how I write code from the ground up.





  • Fewer regression bugs – I no longer worry about forgetting a hidden copy of a number.


  • Faster onboarding – New teammates glance at the constants file and instantly grasp the system’s limits and tuning knobs.


  • Easier experimentation – Tuning a timeout or a batch size becomes a config tweak, not a code dive.


  • Confidence in refactoring – When I extract a method or introduce a new service, I can safely reuse existing constants, knowing they represent the same concept everywhere.



In short, this tiny discipline turned my legacy‑code anxiety into a sense of control—like finally mastering the lightsaber after years of swinging a blunt stick.






Your Turn



Pick a file you’ve been avoiding because it’s full of “magic numbers.” Spend ten minutes extracting those literals into clearly named constants. Run the tests, watch the green lights, and feel the relief of not having to decipher cryptic math every time you read the code.



What’s the first constant you’ll extract? Share your before/after snippets in the comments—I’d love to see how this simple practice transforms your codebase! 🚀

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-Diskussion & Kommentare

🌐 Zum Hauptchat

Starte die Diskussion im Social-Chat Broadcast Stream oder reiche oben über „Information ergänzen“ einen Fachbeitrag ein.

Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
Noch keine Leser-Bewertungen
War dieser Artikel hilfreich?
0
Jetzt Bewertung abgeben
Detail-Bewertung (optional)
Inhalt & Qualität
Quelle & Glaubwürdigkeit
Aktualität
Security Briefing Kostenlos · 1-Klick-Abmeldung

Intelligence Digest — kostenlos

Täglich die wichtigsten Security-News · jederzeit abbestellbar

Verwandte Story-Cluster & Quellen (Vektor-KI)

2 Cluster
2 Quellen
CVE-2026-93653 | Red Hat Enterprise Linux/Hardened Images Splash Backend tilingPatternFill denial of service (EUVD-2026-82931)
VulDB Updates vor 3 Std.
1 weitere Quelle
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Refactoring Legacy Code: A Jedi’s Guide to Clean Code

Thematisch verwandte Begriffe: Refactoring, Legacy, Code, Jedis · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Widgets & Themen
Widgets werden geladen…
Nächster Beitrag