wwbmmm commented on code in PR #3743:
URL: https://github.com/apache/brpc/pull/3743#discussion_r4576645275


##########
src/brpc/builtin/hotspots_service.cpp:
##########
@@ -1063,6 +1065,9 @@ static void StartProfiling(ProfilingType type,
     for (butil::FilePath name = prof_enum.Next(); !name.empty();
          name = prof_enum.Next()) {
         // NOTE: name already includes dir.
+        if (!ValidProfilePath(name.value())) {

Review Comment:
   [replied by brpc-oncall robot] Filtering the listing with 
`ValidProfilePath(name.value())` regresses the page in two ways. 
`ValidProfilePath` validates the whole path, including the configured prefix: 
if `-rpc_profiling_dir` (or the checksum directory under it) contains any 
character outside `[A-Za-z0-9_-/.]` — a space, `+`, `~`, a non-ASCII name — 
every profile is filtered out and the page silently shows an empty list, 
although those profiles were listed before. It also means files with names 
outside the whitelist are no longer pruned by `max_profiles_kept`, so they 
accumulate forever. Since the option values and text are already HTML-escaped, 
the filter is not needed for the injection fix; if you want to hide 
unselectable entries, apply the character check to the entry name only 
(`GetBaseName`).



##########
src/brpc/builtin/common.cpp:
##########
@@ -122,27 +124,36 @@ void PrintRealDateTime(std::ostream& os, int64_t tm,
     }
 }
 
+static std::string EncodeUriPath(const char* path) {

Review Comment:
   [replied by brpc-oncall robot] Encoding the whole URI string has a wider 
impact than the `/dir` round trip: `Path` is also used for the index page links 
that carry brpc's own path syntax, and none of it is percent-decoded by the 
server (`URI::path()`/`FillUnresolvedPath` keep `%xx` verbatim). After this 
change
   - `/flags/guard_page_size;help*` becomes `/flags/guard_page_size%3bhelp%2a`, 
so `FlagsService` (which splits `unresolved_path` on `,;` and looks for `$*`) 
no longer sees the `;help` modifier or the glob;
   - `/vars/rpc_server*_count;iobuf_blo$k_*` loses its `*`, `;` and `$` the 
same way;
   - `/rpcz?__time_str=...&__max_scan=10` becomes a single path segment because 
`?`, `=` and `&` are encoded, so the link no longer has a query at all and 
returns "Fail to find method".
   Those are the usage examples the index page itself advertises, so please do 
not percent-encode the URI here. Keeping only `WebEscape` on the href/text 
(previous revision) fixes the HTML injection without changing any link 
semantics; if `/dir` entries with `?`/`#` should really become openable, that 
needs a percent-encoded path component plus a matching decode in `dir_service`, 
done separately.



##########
src/brpc/builtin/hotspots_service.cpp:
##########
@@ -24,8 +24,10 @@
 #include "butil/popen.h"                         // butil::read_command_output
 #include "butil/fd_guard.h"                      // butil::fd_guard
 #include "butil/iobuf_profiler.h"
+#include "butil/strings/string_util.h"

Review Comment:
   [replied by brpc-oncall robot] These two includes are leftovers from the 
removed prefixed-encoding helpers: `butil/strings/string_util.h` (was for 
`IsHexDigit`) and `brpc/grpc.h` (was for `PercentEncode`/`PercentDecode`) are 
no longer referenced here; the same holds for `brpc/grpc.h` added to 
`test/brpc_builtin_service_unittest.cpp`. Please drop them.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to