The 5 coolest things about using Python

Python has numerous cool features that make it one of the most popular programming languages in the world. Here are five that stand out — with code to prove it. 1. Readability and Simplicity Python’s clean syntax emphasizes readability, making it easy for both beginners and experienced programmers to understand code at a glance: # Reading a file is straightforward and safe with open("data.txt") as f: for line in f: print(line.strip()) The with statement handles resource cleanup automatically. The intent of the code is obvious. Compare this to the equivalent boilerplate in Java or C++ and the difference is striking. ...

March 21, 2023 · 2 min · Carl Sampson

Some XXE Payloads

XML External Entity (XXE) injection exploits applications that parse XML input without disabling external entity resolution. If the XML parser is misconfigured (which many are by default), an attacker can define custom entities that read local files, make network requests, or cause denial of service. These payloads are for authorized security testing only. What is XXE? When an XML parser processes a document, it can resolve entities defined in the DOCTYPE declaration. External entities use the SYSTEM keyword to reference files or URLs. If the parser resolves these without restriction, the attacker controls what the server reads and where it sends data. ...

March 14, 2023 · 3 min · Carl Sampson

Content Security Policy

Content Security Policy (CSP) is a browser security mechanism that controls which resources a web page is allowed to load. By declaring a policy via HTTP header, you tell the browser exactly which scripts, styles, images, fonts, and connections are permitted. Anything not explicitly allowed is blocked. CSP is one of the most effective defenses against Cross-Site Scripting (XSS) and data injection attacks. How CSP Works CSP is delivered as an HTTP response header: ...

February 23, 2023 · 3 min · Carl Sampson

Context Managers in Python

Context managers are Python’s answer to resource management — ensuring that files get closed, locks get released, and database connections get returned to the pool, even when exceptions occur. The with statement makes this pattern concise and reliable. The with Statement The most common context manager is open() for file handling: with open("example.txt", "w") as file: file.write("Hello, World!") # File is automatically closed here, even if write() raises an exception Without with, you’d need a try/finally block: ...

February 22, 2023 · 3 min · Carl Sampson