bneradt commented on code in PR #13807:
URL: https://github.com/apache/trafficserver/pull/13807#discussion_r4201221197


##########
plugins/experimental/jax_fingerprint/README:
##########
@@ -21,7 +21,7 @@ jax_fingerprint/
   log.cc / .h              Optional log file output for fingerprints.
   method.h                 Abstract Method struct (name, type, callbacks).
                            Unaware of any concrete method.
-  config.h                 PluginConfig, parsing helpers.
+  config.cc / config.h     PluginConfig and YAML configuration loading.

Review Comment:
   [P3] Update the method-registration instructions after moving the table
   
   The `METHODS` table and per-method includes now live in `config.cc`, but 
step 3 under "Adding a new method" still instructs developers to register both 
in `plugin.cc`. Following those instructions leaves the YAML loader unaware of 
the new method, so a build with `ENABLE_JAX_METHODS=...;mymethod` still rejects 
`method: MYMETHOD` as unknown. Update that step to name `config.cc` so the 
downstream extension workflow matches the new implementation.



##########
plugins/experimental/jax_fingerprint/config.cc:
##########
@@ -0,0 +1,212 @@
+/** @file
+
+  @section license License
+
+  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.
+ */
+
+#include "config.h"
+
+#ifdef ENABLE_JAX_METHOD_JA4
+#include "ja4/method.h"
+#endif
+#ifdef ENABLE_JAX_METHOD_JA4H
+#include "ja4h/method.h"
+#endif
+#ifdef ENABLE_JAX_METHOD_JA3
+#include "ja3/method.h"
+#endif
+
+#include <yaml-cpp/yaml.h>
+
+#include <algorithm>
+#include <initializer_list>
+#include <string_view>
+
+namespace
+{
+constexpr Method const *METHODS[] = {
+#ifdef ENABLE_JAX_METHOD_JA4
+  &ja4::method,
+#endif
+#ifdef ENABLE_JAX_METHOD_JA4H
+  &ja4h::method,
+#endif
+#ifdef ENABLE_JAX_METHOD_JA3
+  &ja3::method,
+#endif
+};
+
+constexpr std::string_view ROOT_KEY         = "jax_fingerprint";
+constexpr std::string_view FINGERPRINTS_KEY = "fingerprints";
+
+bool
+check_keys(const YAML::Node &node, std::initializer_list<std::string_view> 
allowed, std::string_view scope)
+{
+  for (auto const &entry : node) {
+    auto key = entry.first.as<std::string>();
+    if (std::find(allowed.begin(), allowed.end(), key) == allowed.end()) {

Review Comment:
   [P2] Reject duplicate YAML mapping keys
   
   `check_keys()` checks whether each key is allowed but never checks whether 
it has already appeared. The bundled yaml-cpp accepts repeated keys and 
`node[key]` retrieves the first occurrence, so a fingerprint entry containing 
`standalone: false` followed by `standalone: true` is accepted with standalone 
disabled. Likewise, `mode: overwrite` followed by `mode: invalid` is accepted 
without reporting the invalid value. I reproduced both with this commit's 
loader. This can silently suppress the request hook and fingerprint headers 
when an operator adds a setting to an existing entry, and contradicts the 
advertised rejection of invalid configuration. Track seen keys in this shared 
validation helper and reject duplicates at all three mapping levels; add 
negative coverage for repeated fingerprint settings and repeated `fingerprints` 
keys.



-- 
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