The Class Path Nobody Denied

Hard

· Backend

Incident

SEV-1

BUG-S4S

Priority: Critical · reported by security

Time to fix: 35 min

Failing checks on the shipped build

  • the route through the module property is refused

    no path may travel through class: expected false but got true

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Spring · CVE-2022-22965

Modelled on Spring4Shell (CVE-2022-22965, March 2022): Spring MVC's data binding let request parameters walk a property path from the form object into class.module.classLoader…. An older fix had blocked the path class.classLoader, but on JDK 9+ the class loader was also reachable through the new module property, and on some Tomcat deployments that was enough for remote code execution.

This project is a reconstruction without reflection: the form object is a tree of maps, and every object exposes a class entry just as every Java bean exposes getClass(); the JDK 9 route is the jdkModule entry and the class loader is loader. DataBinder.bind walks the dotted path and sets the leaf — guarded by a denylist of one exact prefix.

Fix bind so no property path can ever travel through class.

Code map

class DataBinder {
    @SuppressWarnings("unchecked")
    static boolean bind(Map<String, Object> target, String path, String value) {
        if (path.toLowerCase().startsWith("class.loader")) return false;
        String[] segs = path.split("\\.");
        Map<String, Object> node = target;
        for (int i = 0; i < segs.length - 1; i++) {
            Object next = node.get(segs[i]);
            if (!(next instanceof Map)) return false;
            node = (Map<String, Object>) next;
        }
        String leaf = segs[segs.length - 1];
        if (!node.containsKey(leaf) || node.get(leaf) instanceof Map) return false;
        node.put(leaf, value);
        return true;
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Class Path Nobody Denied — Java Bug Hunt

Modelled on Spring4Shell (CVE-2022-22965, March 2022): Spring MVC's data binding let request parameters walk a property path from the form object into…

  • Language: Java
  • Layer: Backend
  • Difficulty: Hard
  • Concepts: Security, Validation
  • Modelled on: Spring · CVE-2022-22965
  • Visible tests: a plain property binds; the route through the module property is refused; the old direct route stays refused
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical)
  • Ticket: BUG-S4S
  • Reported by: security
  • Time to fix: 35 minutes, the target for a hard incident

Failing checks on the shipped build

  • the route through the module property is refused — no path may travel through class: expected false but got true

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Modelled on Spring4Shell (CVE-2022-22965, March 2022): Spring MVC's data binding let request parameters walk a property path from the form object into class.module.classLoader…. An older fix had blocked the path class.classLoader, but on JDK 9+ the class loader was also reachable through the new module property, and on some Tomcat deployments that was enough for remote code execution.

This project is a reconstruction without reflection: the form object is a tree of maps, and every object exposes a class entry just as every Java bean exposes getClass(); the JDK 9 route is the jdkModule entry and the class loader is loader. DataBinder.bind walks the dotted path and sets the leaf — guarded by a denylist of one exact prefix.

Fix bind so no property path can ever travel through class.

Bug report

BUG-S4S · Priority: Critical · Reported by: security

DataBinder.bind(target, path, value) walks a dotted path through nested maps and sets the leaf, returning true when it bound and false when it refused.

  • a path is refused (false, nothing changed) if ANY of its segments is "class", compared case-insensitively — wherever it appears in the path
  • a path is refused if an intermediate segment is missing or is not a map
  • a path is refused if the leaf does not already exist or is itself a map (binding only sets existing simple properties)
  • otherwise the leaf is set to value and bind returns true

Observed: class.loader.* is refused, but class.jdkModule.loader.logConfig.pattern binds and rewrites the container's logging pattern.

Logs

[binder] refused class.loader.logConfig.pattern
[binder] bound class.jdkModule.loader.logConfig.pattern = "<attacker text>"

The code as shipped

src/web/DataBinder.java (editable)

class DataBinder {
    @SuppressWarnings("unchecked")
    static boolean bind(Map<String, Object> target, String path, String value) {
        if (path.toLowerCase().startsWith("class.loader")) return false;
        String[] segs = path.split("\\.");
        Map<String, Object> node = target;
        for (int i = 0; i < segs.length - 1; i++) {
            Object next = node.get(segs[i]);
            if (!(next instanceof Map)) return false;
            node = (Map<String, Object>) next;
        }
        String leaf = segs[segs.length - 1];
        if (!node.containsKey(leaf) || node.get(leaf) instanceof Map) return false;
        node.put(leaf, value);
        return true;
    }
}

Read-only context: src/web/FormObject.java.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.