Topic 5.5 · Unit 5: Securing Applications and Data · 20 minute session

5.5 Protecting Applications

Secure by design means companies build security into every phase of product development, including design: they take ownership of customer security outcomes, embrace radical transparency and accountability, and build leadership for it. Secure by default means security features are already on out of the box. Applications wrap user input in control characters (single quote, double quote, semicolon), so a verification function should sanitize input or reject it, which protects against structured query language (SQL) injection, cross site scripting (XSS) and directory traversal attacks.

Big idea Build security in from the first sketch and ship it switched on; then never trust what a user types.

Course and exam description (CED) codes covered: 5.5.A.15.5.A.25.5.A.35.5.B.15.5.B.2

Last reviewed against the CED:

By the end of this session you can

  • 5.5.A Identify the application security principles of secure by design and security by default.
  • 5.5.B Explain how user input sanitization protects applications.

Already know this? Jump to the checkpoint.

1. Secure by design and secure by default (5.5.A)

Secure by design is an initiative that encourages companies to include security in all phases of product development, including design. Security becomes a design principle, not just a technical feature 5.5.A.1. It has three principles 5.5.A.2:

Principle What it looks like
Take ownership of customer security outcomes Build products that meet customers’ security needs
Embrace radical transparency and accountability Share security-related product news and updates quickly, which raises security for everyone
Build organizational structure and leadership Leaders focused on security, with a security-first posture

Secure by default is part of secure by design: security features of software and devices are enabled by default, so products are secure to use out of the box 5.5.A.3. A new smart speaker that forces you to set a unique password at first start, with automatic updates already switched on, is secure by default; one that ships with a shared factory password and updates turned off is not.

2. Input sanitization (5.5.B)

When users type into an application, it usually wraps the input in special characters to process it. These control characters include the single quote, the double quote and the semicolon 5.5.B.1.

Why a quote matters (simplified)
expected:  ... WHERE city = 'Lisbon'
typed:     Lisbon'; DELETE FROM bookings; --
becomes:   ... WHERE city = 'Lisbon'; DELETE FROM bookings; --'
# the quote ends the text, the semicolon starts a new command

Programmers should use a verification function to check that input meets the expected criteria and contains no control characters that could manipulate the system. The function can sanitize the input by removing potentially malicious characters, or give the user an error and make them enter different input 5.5.B.2. For example, removing or encoding the < and > characters means a <script> tag can never form, and removing ../ stops a path from climbing directories. This protects against:

  • SQL injection attacks
  • Cross site scripting (XSS) attacks
  • Directory traversal attacks

Review real form submissions below and decide which ones the verification function should stop.

Lock it in: memory hooks

One picture per idea. If you remember the hook, you can rebuild the details.

  • Secure by design principlesOwn it, share it, lead it: ownership of customer outcomes, radical transparency, security-first leadership.
  • Control charactersQuote, double quote, semicolon: the characters that wrap input.

Common misconceptions

  • "Secure by design is a feature you add at the end."

    Not quite. It makes security a design principle in all phases of product development, not just a technical feature.

  • "Secure by default means the product can be made secure in the settings."

    Not quite. It means security features are already enabled, so the product is secure to use out of the box.

  • "Sanitizing input means encrypting it."

    Not quite. Sanitizing removes potentially malicious characters, or rejects the input and asks for different input.

Simulation · [5.5.B.1, 5.5.B.2, 5.1.B.2]

Input review: which submissions should the sanitizer stop?

These are values typed into the "Order quantity" and "Gift message" fields of an online shop. Quantity should be a whole number from 1 to 20; a gift message is plain text. Tap every input the validation function should reject or sanitize.

form-submissions · shop.example (before processing)
  1. Fine. A whole number between 1 and 20: exactly what the field expects.

  2. Red flag. A semicolon is a control character, followed by an SQL command. A number field should accept only digits.

  3. Red flag. Digits only, but outside the expected range of 1 to 20. Data validation rejects input outside the expected parameters.

  4. Fine. Plain text with ordinary punctuation. Nothing here changes how the program behaves.

  5. Red flag. A script tag: if the shop shows this message on a page, every visitor's browser runs it. That is cross site scripting (XSS).

  6. Red flag. Single quotes are control characters that can close the application's own quotes, and OR '1'='1 is always true: an SQL injection attempt.

  7. Fine. Plain text. Numbers and spaces in a message are normal.

Exam traps

  • The three secure by design principles are about the company: ownership of customer security outcomes, radical transparency and accountability, and organizational structure and leadership.
  • A verification function can either sanitize (remove dangerous characters) or reject the input with an error.
  • Input sanitization protects against SQL injection, XSS and directory traversal attacks.

By the numbers

Say each list out loud, then tap to check.

3 secure by design principles Say them, then tap
  • take ownership of customer security outcomes
  • embrace radical transparency and accountability
  • build organizational structure and leadership
3 control characters Say them, then tap
  • single quote
  • double quote
  • semicolon
3 attacks input sanitization blocks Say them, then tap

In 30 seconds

  1. Secure by design: security in all phases of product development, including design.
  2. Its principles: ownership of customer security outcomes; radical transparency and accountability; organizational structure and leadership for a security-first posture.
  3. Secure by default: security features enabled out of the box.
  4. Control characters (', ", ;) encase user input; a verification function sanitizes or rejects input, protecting against SQL injection, XSS and directory traversal.

Cover this list, say the points out loud, then take the checkpoint without scrolling back up.

Checkpoint · 7 questions

Checkpoint: Protecting Applications

Pick an answer to mark it. Every answer is explained, and you can try any question again. Your saved score counts first tries only, and stays in this browser.

  1. A new home router arrives with automatic updates turned on, its firewall enabled and a unique password printed on a label, with no setup needed.
    1 Which principle does the router follow? 5.5.A.3
    Show answer

    Answer: C. Secure by default means security features are enabled by default, so devices are secure to use out of the box.

  2. A video doorbell maker discovers a flaw, publishes a clear notice about it on the same day, and explains exactly which models need the update.
    2 Which secure by design principle does this action best show? 5.5.A.2
    Show answer

    Answer: B. Sharing relevant security-related product news and updates quickly increases security for everyone: radical transparency and accountability.

  3. 3 Which of the following best describes secure by design? 5.5.A.1
    Show answer

    Answer: A. Secure by design encourages companies to include security in all phases of product development, including design: a design principle, not just a technical feature.

  4. 4 Which set of characters are control characters that applications use to encase user input? 5.5.B.1
    Show answer

    Answer: D. The characters that encase user input are called control characters and include the single quote, the double quote and the semicolon.

  5. A hotel booking form asks for a last name. A verification function checks each input before it is processed.
    Last name inputs
    InputValue
    I1Okonkwo
    I2van der Berg
    I3Smith'; DELETE FROM guests
    I4Nakamura
    5 Which input should the function reject? 5.5.B.2
    Show answer

    Answer: C. A verification function should check that input meets expected criteria and contains no control characters. I3 contains a single quote and a semicolon followed by an SQL command.

  6. 6 A developer adds a function that removes < and > characters from every comment before it is saved. Which attack does this most directly protect against? 5.5.B.2
    Show answer

    Answer: C. Sanitizing user input by removing potentially malicious characters protects against attacks including XSS, which relies on script tags.

  7. 7 Which of the following attacks does input sanitization help protect against? 5.5.B.2, 5.1.B.10
    Show answer

    Answer: C. Verifying and sanitizing user input protects against many application attacks, including SQL injection, XSS and directory traversal.

Key terms: flip the cards

Read the term, say the definition out loud, then flip to check. Struggling a little to remember is what makes it stick.

  • Secure by designtap to flip

    An initiative to include security in all phases of product development, including design; companies own customer security outcomes, are radically transparent and build security-first leadership.

    Example and CED codes
  • Secure by defaulttap to flip

    The idea that security features of software and devices are enabled by default, so products are secure out of the box.

    Example and CED codes
  • Control characterstap to flip

    Characters an application uses to encase user input, including the single quote, the double quote and the semicolon.

    Example and CED codes
  • Input sanitizationtap to flip

    Using a verification function to remove potentially malicious characters from user input, or reject it, before processing.

    Example and CED codes
  • Data validationtap to flip

    Verifying that user input meets the expected criteria, such as digits for a quantity, before processing it, and rejecting anything outside the expected parameters.

    Example and CED codes
  • SQL injectiontap to flip

    An attack that places structured query language (SQL) commands and control characters into an input field, so the application returns too much data or changes and deletes data.

    Example and CED codes
  • Cross site scripting (XSS)tap to flip

    An attack that injects malicious code into a website so the user's browser runs it; Type I is reflected (in a link) and Type II is stored (posted on the site).

    Example and CED codes
  • Directory traversaltap to flip

    An attack that edits uniform resource locators (URLs) and hypertext transfer protocol (HTTP) GET requests, usually with ../, to reach sensitive files outside a web application's folder.

    Example and CED codes

Questions students ask

What is the difference between secure by design and secure by default?

Secure by design puts security into every phase of building a product. Secure by default is part of it: the product ships with its security features already turned on.

What are control characters?

Characters an application uses to encase user input so it can process it: the single quote, the double quote and the semicolon. Adversaries type them to break out of the input and change what the program does.

How does input sanitization protect an application?

A function checks that the input meets the expected criteria and contains no control characters. It removes potentially malicious characters or makes the user enter something else, blocking SQL injection, XSS and directory traversal.

Was this page helpful?

Please do not include personal details. To get a reply, email [email protected].

Contents
↑ Top

Enlarged view of the selected figure