Skip to content

Harden the player head skin fetch and Mojang client - #119

Open
Aerhhh wants to merge 1 commit into
masterfrom
security/player-head-fetch
Open

Aerhhh wants to merge 1 commit into
masterfrom
security/player-head-fetch

Conversation

@Aerhhh

@Aerhhh Aerhhh commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Why

Follow-up to the security review (see #116). The player head generator fetched skins over plain HTTP with no size limit, let some caller text through into the request path, and built new HTTP clients on every use.

What changed

Skin fetch (MinecraftPlayerHeadGenerator)

  • Skins are fetched from https://textures.minecraft.net and redirects are not followed. Previously it was http://, so anyone on the network path could substitute the image.
  • Only a bare alphanumeric texture ID is requested. Input longer than 16 characters that matched none of the known forms used to be appended to the URL as-is (../, ?query, and so on); it is now rejected. The url inside a base64 texture value contributes only its last path segment.
  • The download is capped at 1 MiB, and the PNG header size is checked (64x32 up to 1024x1024) before any pixels are decoded. Only the PNG reader is used.
  • scale is clamped: at most 4x up (the head render is already 1250 px square) and 64x down.

Mojang client (MojangApiClientFactory)

  • New sharedInstance(), used by the generator's builder. defaultInstance() built two java.net.http.HttpClients on every Builder.build().
  • Explicit timeouts (5 s connect, 10 s read), no redirects.

Error handling

  • A null or blank skin, and base64 values with a missing or mistyped textures / SKIN / url, now fail with GeneratorException instead of NullPointerException or ClassCastException.

Behaviour changes to be aware of

  • withScale above 4 or below -64 is clamped silently.
  • A null skin now fails with a clear message. Heads.besideTooltip documents null as "the default head", but that path always threw; no default head asset exists in the repo.

Testing

  • Seven tests added to MinecraftPlayerHeadGeneratorTest, none needing the network: size limits, non-PNG content, path-changing texture IDs, missing skin, malformed texture values.
  • MinecraftPlayerHeadGeneratorTest, ItemToolTest and DialogueToolTest: 29 tests pass.
  • Checked by hand against the live services: a texture hash and a player name both render.
  • The full suite was not run locally.

- Fetch skins over HTTPS, without following redirects.
- Only request a bare alphanumeric texture ID; reject anything else
  instead of appending it to the texture host URL.
- Cap the skin download at 1 MiB and check the PNG header size
  (64x32 to 1024x1024) before decoding.
- Clamp upscale to 4x and downscale to 64x.
- Share one Mojang API client with explicit timeouts instead of building
  two HTTP clients per generator.
- Report a missing skin and malformed texture values as
  GeneratorException instead of NullPointerException and
  ClassCastException.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant