mrdevel2002-ui opened a new pull request, #3605:
URL: https://github.com/apache/tika/pull/3605

   `tika-server` listens on `localhost` by default and does no authentication, 
so on a developer machine or a host without a firewall the loopback bind is 
what keeps other parties out. A web page in a browser on that machine gets past 
it by DNS rebinding: it serves itself from `rebind.attacker.example:9998`, then 
answers the next lookup of that name with 127.0.0.1. From then on its `fetch()` 
calls go to the local server but count as same-origin, so they need no 
preflight, may send `Content-Type: application/json` (the `@Consumes` check 
#3442 put on `/pipes` and `/async` does not apply) and can read the responses. 
With `allowPipes` that means `/pipes` and `/async` with the operator's 
fetchers, emitters and credentials, the same reach the CSRF fix removed for 
cross-site pages; without it, every parse endpoint. What the server does see is 
the page's domain in the `Host` header, and Jetty and CXF answered whatever it 
said: `GET /status` with `Host: rebind.attacker.example:<port>` against
  a `TikaServerProcess` bound to `localhost` returns `200` on main.
   
   `LoopbackHostFilter` is a pre-matching request filter registered with the 
other server filters in `TikaServerProcess.loadAllProviders`. When the 
configured `host` resolves only to loopback addresses, a request whose `Host` 
is not `localhost`, `*.localhost`, a loopback IP literal or the configured host 
gets `403`. IP literals are parsed by hand, or as bracketed IPv6, so a request 
never triggers a DNS lookup. A request with no `Host` (HTTP/1.0) is let 
through, since browsers always send one. The filter runs at priority 200: after 
`TikaMetricsFilter`, so refusals are counted, and before CXF's CORS filter.
   
   The trade-off is reverse proxies on the same machine, which now have to send 
a loopback `Host`. nginx does by default; Caddy, Traefik and Apache with 
`ProxyPreserveHost On` forward the client's and would get `403`, which the 
server docs and CHANGES now say. I limited the check to loopback binds because 
there the set of valid names is known. A server bound to `0.0.0.0`, as in the 
Docker image, can legitimately be reached under any name, so it is unchanged; 
covering it would need an operator-supplied list of names. Happy to add an 
`allowedHosts` setting for either case if you would rather have that escape 
hatch in the config than in the proxy.
   
   `LoopbackHostFilterTest` drives a real Jetty over raw sockets: `localhost`, 
`localhost.`, `127.x.y.z`, `[::1]` and `tika.localhost` are served, while 
`rebind.attacker.example`, `localhost.attacker.example`, 
`127.0.0.1.attacker.example`, a LAN IP and a non-loopback IPv6 literal get 
`403`. `TikaServerBasicIntegrationTest.testForeignHostRefusedOnLoopback` pins 
the wiring in the real server process. With the filter disabled both fail with 
`200`. `./mvnw clean apache-rat:check install -Pci` is green for 
tika-server-core (252 tests) and tika-server-standard (147 tests) on JDK 21, 
including checkstyle, spotless and forbidden-apis.
   
   - [ ] open issue on the Tika issue tracker: not filed yet, happy to open one 
or have it linked
   - [ ] issue ID in the PR title and commit message: pending the issue above
   - [x] commits are squashed into a single one
   - [x] Tika builds and unit tests pass with `./mvnw clean install` (affected 
modules)
   - [x] no conflicts with the recent `main` branch
   - [ ] new downstream module added to `tika-bom/pom.xml`: not applicable
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to