You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tika.apache.org by "tballison (via GitHub)" <gi...@apache.org> on 2026/10/16 21:02:53 UTC

[PR] TIKA-4974: enforce @OperatorOnly wherever a request builds a component [tika]

tballison opened a new pull request, #3352:
URL: https://github.com/apache/tika/pull/3352

   <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
     regarding copyright ownership.  The ASF licenses this file
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
   -->
   
   Thanks for your contribution to [Apache Tika](https://tika.apache.org/)! Your help is appreciated!
   
   Before opening the pull request, please verify that
   * there is an open issue on the [Tika issue tracker](https://issues.apache.org/jira/projects/TIKA) which describes the problem or the improvement. We cannot accept pull requests without an issue because the change wouldn't be listed in the release notes.
   * the issue ID (`TIKA-XXXX`)
     - is referenced in the title of the pull request
     - and placed in front of your commit messages surrounded by square brackets (`[TIKA-XXXX] Issue or pull request title`)
   * commits are squashed into a single one (or few commits for larger changes)
   * Tika builds and unit tests pass with `./mvnw clean install` (`clean test` alone cannot resolve the pipes plugin zips)
   * if you used a generative AI tool: follow the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) (`Generated-by: <tool>` in the commit message), and consider running the pre-flight in `.skills/devs/pr-review/SKILL.md` — fix what it finds; don't paste its report here
   * there should be no conflicts when merging the pull request branch into the *recent* `main` branch. If there are conflicts, please try to rebase the pull request branch on top of a freshly pulled `main` branch
   * if you add new module that downstream users will depend upon add it to relevant group in `tika-bom/pom.xml`.
   
   We will be able to faster integrate your pull request if these conditions are met. If you have any questions how to fix your problem or about using Tika in general, please sign up for the [Tika mailing list](http://tika.apache.org/mail-lists.html). Thanks!
   


-- 
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: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] TIKA-4974: enforce @OperatorOnly wherever a request builds a component [tika]

Posted by "tballison (via GitHub)" <gi...@apache.org>.
tballison merged PR #3352:
URL: https://github.com/apache/tika/pull/3352


-- 
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: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] TIKA-4974: enforce @OperatorOnly wherever a request builds a component [tika]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3352:
URL: https://github.com/apache/tika/pull/3352#discussion_r4301776803


##########
tika-serialization/src/main/java/org/apache/tika/config/loader/ComponentInstantiator.java:
##########
@@ -225,6 +238,43 @@ public static <T> T instantiateComponent(String typeName, JsonNode configNode,
         }
     }
 
+    /**
+     * Refuses what per-request JSON may not build: a class of a request-blocked type, a class
+     * marked {@link OperatorOnly}, or config naming an {@code @OperatorOnly} property. Runs
+     * before construction, since constructing a component can have side effects.
+     */
+    public static void assertRequestMayConfigure(String typeName, Class<?> clazz,
+                                                 JsonNode config, ObjectMapper mapper)
+            throws TikaConfigException {
+        if (ComponentNameResolver.isWireBlockedClass(clazz)) {
+            throw new TikaConfigException("Component '" + typeName + "' (" + clazz.getName()
+                    + ") may not be supplied via a request parseContext. It must be configured "
+                    + "server-side in the Tika config, not at request time.");
+        }
+        try {
+            OperatorOnlyGuard.check(mapper, typeName, config, mapper.constructType(clazz));
+        } catch (IOException e) {
+            throw new TikaConfigException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Carries the request's trust into the components a config nests: Jackson builds them
+     * through {@code TikaModule}, which reads {@link #UNTRUSTED} back.
+     */
+    public static ObjectReader withTrust(ObjectReader reader, boolean trusted) {
+        return trusted ? reader : reader.withAttribute(UNTRUSTED, Boolean.TRUE);
+    }
+
+    /** True if {@code ctxt} is reading per-request JSON (see {@link #withTrust}). */

Review Comment:
   This Javadoc reverses the return value: per-request JSON carries the `UNTRUSTED` attribute, so `isTrusted()` returns false. Document the trusted case to avoid misleading callers of this security-sensitive predicate.



-- 
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: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] TIKA-4974: enforce @OperatorOnly wherever a request builds a component [tika]

Posted by "tballison (via GitHub)" <gi...@apache.org>.
tballison commented on PR #3352:
URL: https://github.com/apache/tika/pull/3352#issuecomment-6224654203

   This is based on the point made here: https://github.com/apache/tika/pull/3351 We should make this easier not to get wrong.


-- 
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: dev-unsubscribe@tika.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org