1 /*
2 * Copyright 2026 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.handler.codec.http3;
17
18 /**
19 * Determines whether a header field is sensitive, in which case the QPACK encoder
20 * <ul>
21 * <li>MUST NOT insert it into the dynamic table, and</li>
22 * <li>MUST encode it as a literal with the "Never Indexed" ({@code N=1}) flag
23 * set as defined in
24 * <a href="https://www.rfc-editor.org/rfc/rfc9204.html#section-4.5.4">RFC 9204 4.5.4</a>
25 * through <a href="https://www.rfc-editor.org/rfc/rfc9204.html#section-4.5.7">4.5.7</a>.</li>
26 * </ul>
27 *
28 * <p>This mirrors {@code io.netty.handler.codec.http2.Http2HeadersEncoder.SensitivityDetector}
29 * from the HTTP/2 / HPACK side.</p>
30 *
31 * <p>Setting {@code N=1} prevents intermediaries from inserting the field into
32 * their own dynamic tables, which mitigates information disclosure via
33 * compression-based side channels (RFC 9204 7.1) for credentials such as
34 * {@code Authorization}, {@code Cookie}, {@code Set-Cookie} and
35 * {@code Proxy-Authorization}.</p>
36 * If the object can be dynamically modified and shared across multiple connections it may need to be thread safe.
37 */
38 public interface QpackSensitivityDetector {
39
40 /**
41 * Treats every header field as non-sensitive. This is the historical default
42 * behaviour of the QPACK encoder and is the backward-compatible choice.
43 */
44 QpackSensitivityDetector NEVER_SENSITIVE = (name, value) -> false;
45
46 /**
47 * Treats every header field as sensitive.
48 */
49 QpackSensitivityDetector ALWAYS_SENSITIVE = (name, value) -> true;
50
51 /**
52 * Determine if a header {@code name}/{@code value} pair is sensitive.
53 *
54 * @param name the header field name.
55 * @param value the header field value.
56 * @return {@code true} if the field is sensitive and must be encoded with
57 * {@code N=1} and excluded from the dynamic table; {@code false}
58 * otherwise.
59 */
60 boolean isSensitive(CharSequence name, CharSequence value);
61 }