Skip to content

Commit

Permalink
Dynamic Sink Support
Browse files Browse the repository at this point in the history
Added support to dynamically insert custom sinks by inserting
`foxhound_sink(str, name)` calls.
  • Loading branch information
leeN committed Jan 27, 2025
1 parent b397c04 commit cae7ebf
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions js/src/builtin/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ static bool str_encodeURI_Component(JSContext* cx, unsigned argc, Value* vp);

static bool str_foxhound(JSContext* cx, unsigned argc, Value* vp);

static bool foxhound_sink(JSContext* cx, unsigned argc, Value* vp);

/*
* Global string methods
*/
Expand Down Expand Up @@ -734,6 +736,7 @@ static const JSFunctionSpec string_functions[] = {
JS_FN("decodeURIComponent", str_decodeURI_Component, 1, JSPROP_RESOLVING),
JS_FN("encodeURIComponent", str_encodeURI_Component, 1, JSPROP_RESOLVING),
JS_FN("foxhound", str_foxhound, 1, JSPROP_RESOLVING),
JS_FN("foxhound_sink", foxhound_sink, 2, JSPROP_RESOLVING),
JS_FS_END,
};

Expand Down Expand Up @@ -5335,6 +5338,25 @@ JSString* js::EncodeURI(JSContext* cx, const char* chars, size_t length) {
return sb.finishString();
}

static bool foxhound_sink(JSContext* cx, unsigned argc, Value* vp) {
AutoJSMethodProfilerEntry pseudoFrame(cx, "foxhound_sink");
CallArgs args = CallArgsFromVp(argc, vp);
RootedString str(cx, ArgToLinearString(cx, args, 0));
if (!str) {
return false;
}

RootedString sink(cx, ArgToLinearString(cx, args, 1));
if (!sink) {
return false;
}
UniqueChars sinkchars = JS_EncodeStringToUTF8(cx, sink);
JS_ReportTaintSink(cx, str, sinkchars.get());

args.rval().setUndefined();
return true;
}

static bool str_foxhound(JSContext* cx, unsigned argc, Value* vp) {
AutoJSMethodProfilerEntry pseudoFrame(cx, "foxhound");
CallArgs args = CallArgsFromVp(argc, vp);
Expand Down

0 comments on commit cae7ebf

Please sign in to comment.