Bird
0
0

Identify the error in this Flask code that tries to add a Strict-Transport-Security header:

medium📝 Debug Q14 of 15
Flask - Security Best Practices
Identify the error in this Flask code that tries to add a Strict-Transport-Security header:
from flask import Flask
app = Flask(__name__)

@app.after_request
def secure_headers(response):
    response.headers['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains'
    return response

@app.route('/')
def index():
    return 'Welcome'
AThe header name should be lowercase
BNo error; the code is correct
CThe header value string is missing quotes
DThe function must accept two parameters
Step-by-Step Solution
Solution:
  1. Step 1: Review header name and value syntax

    Header names are case-insensitive; using 'Strict-Transport-Security' is valid. The value is a valid string with quotes.
  2. Step 2: Check function signature and usage

    @app.after_request functions take one parameter (response) and return it. This matches the code.
  3. Final Answer:

    No error; the code is correct -> Option B
  4. Quick Check:

    Header added correctly in @app.after_request [OK]
Quick Trick: Check function signature and header syntax carefully [OK]
Common Mistakes:
MISTAKES
  • Thinking header names must be lowercase
  • Expecting two parameters in after_request function
  • Missing quotes around header value string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes