Next.js · Middle · Question 54 of 75

Where can you add security headers like X-Frame-Options to all responses without touching pages?

async headers() {
  return [{ source: '/(.*)', headers: [{ key: 'X-Frame-Options', value: 'DENY' }] }]
}

Explanation

Config headers apply by path pattern. Headers that depend on the request, like a CSP nonce, are set in proxy.ts.

Further reading

Problem with a question

Next.js · Middle · question 54

Test yourself

Take the Next.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz