GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Regression 4.2.8.Final - HttpUtil.isEncodingSafeStartLineToken incorrectly rejects valid URI characters 'J' and 'M' due to bit-shift modulo behavior · Issue #16034 · netty/netty

Regression 4.2.8.Final - HttpUtil.isEncodingSafeStartLineToken incorrectly rejects valid URI characters 'J' and 'M' due to bit-shift modulo behavior #16034

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
Regression 4.2.8.Final - HttpUtil.isEncodingSafeStartLineToken incorrectly rejects valid URI characters 'J' and 'M' due to bit-shift modulo behavior#16034
Copy link

Description

@pvillard31
pvillard31
opened on Dec 13, 2025
Issue body actions

Summary

The security fix in commit 2f2e437 introduced a bug where valid ASCII characters 'J' (uppercase), 'M' (uppercase), and '`' (backtick) are incorrectly rejected as "illegal characters" in HTTP request URIs.

Environment

  • Netty version: 4.2.8.Final
  • Java version: Any

Expected Behavior

Valid URIs containing uppercase 'J' or 'M' characters should be accepted. For example:

/bucket/object?uploadId=ABC123MNO456JKL789

Actual Behavior

URIs containing 'J' or 'M' are rejected with:

java.lang.IllegalArgumentException: The URI contain illegal characters: /bucket/object?uploadId=ABC123MNO456JKL789

Root Cause

The issue is in HttpUtil.java:

private static final long ILLEGAL_REQUEST_LINE_TOKEN_OCTET_MASK = 1L << '\n' | 1L << '\r' | 1L << ' ';

The check uses:

long ch = 1L << token.charAt(i);
if ((ch & ILLEGAL_REQUEST_LINE_TOKEN_OCTET_MASK) != 0) {
    return false;
}

The problem: Java's << operator uses modulo 64 for the right operand when the left operand is a long. This causes character values ≥ 64 to collide with the blocked characters:

Character ASCII Value value % 64 Collides With
\n 10 10 (intended)
\r 13 13 (intended)
32 32 (intended)
J 74 10 \n ❌
M 77 13 \r ❌
` 96 32 ❌

Reproduction

import io.netty.handler.codec.http.HttpUtil;

public class Test {
    public static void main(String[] args) {
        // This should return true but returns false in 4.2.8.Final
        System.out.println(HttpUtil.isEncodingSafeStartLineToken("/path?id=JKL"));  // false (wrong!)
        System.out.println(HttpUtil.isEncodingSafeStartLineToken("/path?id=MNO"));  // false (wrong!)
        System.out.println(HttpUtil.isEncodingSafeStartLineToken("/path?id=ABC"));  // true (correct)
    }
}

Impact

This breaks any HTTP client using Netty 4.2.8.Final that sends requests with URIs containing 'J' or 'M' characters.

Suggested Fix

Replace the bit-shift approach with direct character comparison:

public static boolean isEncodingSafeStartLineToken(CharSequence token) {
    for (int i = 0; i < token.length(); i++) {
        char c = token.charAt(i);
        if (c == '\n' || c == '\r' || c == ' ') {
            return false;
        }
    }
    return true;
}

Activity

  1. yawkat commented on Dec 13, 2025

    @yawkat
    yawkat
    on Dec 13, 2025
    Contributor
    More actions

    Duplicate #16020

  2. yawkat
    closed this as a duplicateof Exception will be thrown if uri string contains the character 'M'. #16020 on Dec 13, 2025
  3. franz1981 commented on Dec 13, 2025

    @franz1981
    franz1981
    on Dec 13, 2025
    Contributor
    More actions

    See #16030

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.