Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic sources and sinks #250

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion 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 All @@ -141,9 +143,17 @@ js::str_tainted(JSContext* cx, unsigned argc, Value* vp)
if (!str || str->length() == 0)
return false;

std::string source("manual taint source");
if(args.length() >= 2 && args.hasDefined(1)) {
RootedString src_str(cx, ArgToLinearString(cx, args, 1));
if (src_str && src_str->length() > 0) {
UniqueChars src = JS_EncodeStringToLatin1(cx, src_str);
source = std::string(src.get());
}
}
// We store the string as argument for a manual taint operation. This way it's easy to see what
// the original value of a manually tainted string was for debugging/testing.
TaintOperation op = TaintOperation("manual taint source", true, TaintLocationFromContext(cx), { taintarg(cx, str) });
TaintOperation op = TaintOperation(source.c_str(), true, TaintLocationFromContext(cx), { taintarg(cx, str) });
op.setSource();
SafeStringTaint taint(0, str->length(), op);

Expand Down Expand Up @@ -726,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 @@ -5327,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_EncodeStringToLatin1(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
Loading