@@ -1148,28 +1148,6 @@ rops_handle_POLLIN_quic(struct lws_context_per_thread *pt, struct lws *wsi,
11481148 break ;
11491149 }
11501150
1151- /* Check reserved bits AFTER unmasking! */
1152- if (p [0 ] & 0x80 ) {
1153- /* Long header: Bits 0x0c MUST be zero */
1154- if (p [0 ] & 0x0c ) {
1155- lwsl_wsi_notice (wsi , "QUIC RX: Reserved bits non-zero in long header" );
1156- if (nwsi && nwsi != wsi ) {
1157- lws_quic_enter_closing_state (nwsi , LWS_QUIC_ERR_PROTOCOL_VIOLATION , 0 , 0 );
1158- goto next_packet ;
1159- }
1160- return LWS_HPI_RET_PLEASE_CLOSE_ME ;
1161- }
1162- } else {
1163- /* Short header: Bits 0x18 MUST be zero */
1164- if (p [0 ] & 0x18 ) {
1165- lwsl_wsi_notice (wsi , "QUIC RX: Reserved bits non-zero in short header" );
1166- if (nwsi && nwsi != wsi ) {
1167- lws_quic_enter_closing_state (nwsi , LWS_QUIC_ERR_PROTOCOL_VIOLATION , 0 , 0 );
1168- goto next_packet ;
1169- }
1170- return LWS_HPI_RET_PLEASE_CLOSE_ME ;
1171- }
1172- }
11731151
11741152 /*
11751153 * Reconstruct full 62-bit PN.
@@ -1221,6 +1199,29 @@ rops_handle_POLLIN_quic(struct lws_context_per_thread *pt, struct lws *wsi,
12211199 goto next_packet ;
12221200 }
12231201
1202+ /* Check reserved bits AFTER successful AEAD decryption (RFC 9000 5.4.1 & 12.2) */
1203+ if (p [0 ] & 0x80 ) {
1204+ /* Long header: Bits 0x0c MUST be zero */
1205+ if (p [0 ] & 0x0c ) {
1206+ lwsl_wsi_notice (wsi , "QUIC RX: Reserved bits non-zero in long header" );
1207+ if (nwsi && nwsi != wsi ) {
1208+ lws_quic_enter_closing_state (nwsi , LWS_QUIC_ERR_PROTOCOL_VIOLATION , 0 , 0 );
1209+ goto next_packet ;
1210+ }
1211+ return LWS_HPI_RET_PLEASE_CLOSE_ME ;
1212+ }
1213+ } else {
1214+ /* Short header: Bits 0x18 MUST be zero */
1215+ if (p [0 ] & 0x18 ) {
1216+ lwsl_wsi_notice (wsi , "QUIC RX: Reserved bits non-zero in short header" );
1217+ if (nwsi && nwsi != wsi ) {
1218+ lws_quic_enter_closing_state (nwsi , LWS_QUIC_ERR_PROTOCOL_VIOLATION , 0 , 0 );
1219+ goto next_packet ;
1220+ }
1221+ return LWS_HPI_RET_PLEASE_CLOSE_ME ;
1222+ }
1223+ }
1224+
12241225 /* Decryption succeeded! Commit key update if pending */
12251226 if (is_key_update ) {
12261227 lws_quic_keys_release_aead_rx (k );
0 commit comments