The app that started the collaborative editing revolution is back. Write articles, code, notes or meeting minutes with friends – wherever they are. Ideal for extreme programming sessions, tutoring and creative writing. And now it is free and open source!
H̵e̵l̵l̵o̵ ̵t̵e̵x̵t̵ ̵s̵t̵r̵i̵n̵g̵ ̵m̵y̵ ̵o̵l̵d̵ ̵f̵r̵i̵e̵n̵d̵.̵
H̶e̶l̶l̶o̶ ̶t̶e̶x̶t̶ ̶s̶t̶r̶i̶n̶g̶ ̶m̶y̶ ̶o̶l̶d̶ ̶f̶r̶i̶e̶n̶d̶.̶
H̷e̷l̷l̷o̷ ̷t̷e̷x̷t̷ ̷s̷t̷r̷i̷n̷g̷ ̷m̷y̷ ̷o̷l̷d̷ ̷f̷r̷i̷e̷n̷d̷.̷
H̸e̸l̸l̸o̸ ̸t̸e̸x̸t̸ ̸s̸t̸r̸i̸n̸g̸ ̸m̸y̸ ̸o̸l̸d̸ ̸f̸r̸i̸e̸n̸d̸.̸
e̴l̴l̴o̴ ̴t̴e̴x̴t̴ ̴s̴t̴r̴i̴n̴g̴ ̴m̴y̴ ̴o̴l̴d̴ ̴f̴r̴i̴e̴n̴d̴.̴
Stop!
You're making a mistake here. Oh, no, you've picked the right PHP functions to make your data a bit safer. That's fine. Your mistake is in the order of operations, and how and where to use these functions.
It's important to understand the difference between sanitizing and validating user data, escaping data for storage, and escaping data for presentation.
Sanitizing and Validating User Data
When users submit data, you need to make sure that they've provided something you expect.
Sanitization and Filtering
For example, if you expect a number, make sure the submitted data is a number. You can also cast user data into other types. Everything submitted is initially treated like a string, so forcing known-numeric data into being an integer or float makes sanitization fast and painless.
What about free-form text fields and textareas? You need to make sure that there's nothing unexpected in those fields. Mainly, you need to make sure that fields that should not have any HTML content do not actually contain HTML. There are two ways you can deal with this problem.
First, you can try escaping HTML input with htmlspecialchars. You should not use htmlentities to neutralize HTML, as it will also perform encoding of accented and other characters that it thinks also need to be encoded.
Second, you can try removing any possible HTML. strip_tags is quick and easy, but also sloppy. HTML Purifier does a much more thorough job of both stripping out all HTML and also allowing a selective whitelist of tags and attributes through.
Modern PHP versions ship with the filter extension, which provides a comprehensive way to sanitize user input.
Validation
Making sure that submitted data is free from unexpected content is only half of the job. You also need to try and make sure that the data submitted contains values you can actually work with.
If you're expecting a number between 1 and 10, you need to check that value. If you're using one of those new fancy HTML5-era numeric inputs with a spinner and steps, make sure that the submitted data is in line with the step.
If that data came from what should be a drop-down menu, make sure that the submitted value is one that appeared in the menu.
What about text inputs that fulfill other needs? For example, date inputs should be validated through strtotime or the DateTime class. The given date should be between the ranges you expect. What about email addresses? The previously mentioned filter extension can check that an address is well-formed, though I'm a fan of the is_email library.
The same is true for all other form controls. Have radio buttons? Validate against the list. Have checkboxes? Validate against the list. Have a file upload? Make sure the file is of an expected type, and treat the filename like unfiltered user data.
Every modern browser comes with a complete set of developer tools built right in, which makes it trivial for anyone to manipulate your form. Your code should assume that the user has completely removed all client-side restrictions on form content!
Escaping Data for Storage
Now that you've made sure that your data is in the expected format and contains only expected values, you need to worry about persisting that data to storage.
Every single data storage mechanism has a specific way to make sure data is properly escaped and encoded. If you're building SQL, then the accepted way to pass data in queries is through prepared statements with placeholders.
One of the better ways to work with most SQL databases in PHP is the PDO extension. It follows the common pattern of preparing a statement, binding variables to the statement, then sending the statement and variables to the server. If you haven't worked with PDO before here's a pretty good MySQL-oriented tutorial.
Some SQL databases have their own specialty extensions in PHP, including SQL Server, PostgreSQL and SQLite 3. Each of those extensions has prepared statement support that operates in the same prepare-bind-execute fashion as PDO. Sometimes you may need to use these extensions instead of PDO to support non-standard features or behavior.
MySQL also has its own PHP extensions. Two of them, in fact. You only want to ever use the one called mysqli. The old "mysql" extension has been deprecated and is not safe or sane to use in the modern era.
I'm personally not a fan of mysqli. The way it performs variable binding on prepared statements is inflexible and can be a pain to use. When in doubt, use PDO instead.
If you are not using an SQL database to store your data, check the documentation for the database interface you're using to determine how to safely pass data through it.
When possible, make sure that your database stores your data in an appropriate format. Store numbers in numeric fields. Store dates in date fields. Store money in a decimal field, not a floating point field. Review the documentation provided by your database on how to properly store different data types.
Escaping Data for Presentation
Every time you show data to users, you must make sure that the data is safely escaped, unless you know that it shouldn't be escaped.
When emitting HTML, you should almost always pass any data that was originally user-supplied through htmlspecialchars. In fact, the only time you shouldn't do this is when you know that the user provided HTML, and that you know that it's already been sanitized it using a whitelist.
Sometimes you need to generate some Javascript using PHP. Javascript does not have the same escaping rules as HTML! A safe way to provide user-supplied values to Javascript via PHP is through json_encode.
And More
There are many more nuances to data validation.
For example, character set encoding can be a huge trap. Your application should follow the practices outlined in "UTF-8 all the way through". There are hypothetical attacks that can occur when you treat string data as the wrong character set.
Earlier I mentioned browser debug tools. These tools can also be used to manipulate cookie data. Cookies should be treated as untrusted user input.
Data validation and escaping are only one aspect of web application security. You should make yourself aware of web application attack methodologies so that you can build defenses against them.
Get a trusted software to transfer and save your music, messages, files and data. Safely back up any iPhone, iPad or iPod touch. Powerful and user-friendly, iMazing is simply the best iOS device manager for Mac and PC.
Go beyond iTunes. Get iMazing.
Caption takes the effort out of finding and setting up the right subtitles. A simple design, drag & drop search, and automatic downloading & renaming let you just start watching. Caption is multi-platform, open-source, and built entirely on web technology.
Tips for downloading from Google Drive
There are a few things you can do to make it easier for yourself when downloading stuff from Google Drive.
- There is a quota for files that are shared publicly. If you try to download a file from someone elses Google Drive and it says that the file is unavailable, this quota has been reached.
- To work around this quota, you can always make a copy of the file to your own Google Drive. Right-click the file and select "Make a copy": This will create a copy of the file in your own Google Drive with the prefix "Copy of"
- You can't make a copy of a folder, only individual files. What you can do is to select all the files in a folder and make a copy of those.
- "Add to My Drive" is not the same as "Make a Copy". If you select this, all you are doing is creating a "shortcut" to the file to its original location. This will not help with download-quotas and stuff like that.
- If you have the free version of Google Drive, you will only be able to store 15 gigs on it.
- Even if you have a paid for Google Drive account with unlimited storage, you still have a quota of 750GB of file transfers per day. So if you try to "Make a copy" of all the XCI-files for example, the process will fail when it has copied about 750GB of them. To make a copy of the rest, you'll have to wait 24 hours, or use another Google-account.
- If you have a Google-account through your school or university, you most likely have unlimited storage. Log on to Google Drive and check the left sidebar. If the Storage-indicator doesn't have a limit, you have unlimited storage.
- If you you have a Google-account through school, university or work, the admin can see all your files without you knowing. Google won't care what you store on your Google-drive as long as you don't share it.
Elise's XCI installer, based on tinfoil
WireGuard® is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPSec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. Initially released for the Linux kernel, it is now cross-platform and widely deployable. It is currently under heavy development, but already it might be regarded as the most secure, easiest to use, and simplest VPN solution in the industry.
TegraRcmSmash
CSP Evaluator allows developers and security experts to check if a Content Security Policy (CSP) serves as a strong mitigation against cross-site scripting attacks. It assists with the process of reviewing CSP policies, which is usually a manual task, and helps identify subtle CSP bypasses which undermine the value of a policy. CSP Evaluator checks are based on a large-scale study and are aimed to help developers to harden their CSP and improve the security of their applications. This tool (also available as a Chrome extension) is provided only for the convenience of developers and Google provides no guarantees or warranties for this tool.
The new Content-Security-Policy HTTP response header helps you reduce XSS risks on modern browsers by declaring, which dynamic resources are allowed to load.
How Can Tabula Help Me?
If you’ve ever tried to do anything with data provided to you in PDFs, you know how painful it is — there's no easy way to copy-and-paste rows of data out of PDF files. Tabula allows you to extract that data into a CSV or Microsoft Excel spreadsheet using a simple, easy-to-use interface. Tabula works on Mac, Windows and Linux.
A simple menubar app to connect to your AirPods in a click.