From 14c84e22a971c00dc89c1a793658f356debd4599 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 16 Jan 2025 18:38:32 +0100 Subject: [PATCH] Issue #2676 - Implement AbortSignal.timeout() This is a stub implementation because of the considerable abuse risk and bad web code risk causing DoS, e.g. when using bad timeout values and callbacks on the AbortSignal (e.g. recursive). Considering the abort-ability of these signals otherwise there is never a guarantee to websites that these signals will be triggered anyway, so it should be considered an optional signal - meaning we can safely just ignore the timeout, which allows us to avoid a ton of complexity and potential sec/privacy issues. Primary use in the wild seems to be detailed profiling/ad metrics anyway; we don't really want to encourage that! --- dom/abort/AbortSignal.cpp | 9 +++++++++ dom/abort/AbortSignal.h | 4 ++++ dom/webidl/AbortSignal.webidl | 2 ++ 3 files changed, 15 insertions(+) diff --git a/dom/abort/AbortSignal.cpp b/dom/abort/AbortSignal.cpp index c1255a4e3b..b05f9db52b 100644 --- a/dom/abort/AbortSignal.cpp +++ b/dom/abort/AbortSignal.cpp @@ -49,6 +49,15 @@ already_AddRefed AbortSignal::Abort(GlobalObject& aGlobal) { return abortSignal.forget(); } +already_AddRefed AbortSignal::Timeout(GlobalObject& aGlobal, uint64_t aMilliseconds) { + nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); + + // Stub implementation, just return an AbortSignal object + RefPtr abortSignal = new AbortSignal(global, false); + + return abortSignal.forget(); +} + bool AbortSignal::Aborted() const { diff --git a/dom/abort/AbortSignal.h b/dom/abort/AbortSignal.h index 3cd8402cc4..b53ea3319a 100644 --- a/dom/abort/AbortSignal.h +++ b/dom/abort/AbortSignal.h @@ -47,9 +47,13 @@ public: Aborted() const; void Abort(); + void Timeout(); IMPL_EVENT_HANDLER(abort); + IMPL_EVENT_HANDLER(timeout); + static already_AddRefed Abort(GlobalObject& aGlobal); + static already_AddRefed Timeout(GlobalObject& aGlobal, uint64_t aMilliseconds); void AddFollower(Follower* aFollower); diff --git a/dom/webidl/AbortSignal.webidl b/dom/webidl/AbortSignal.webidl index 1d3525505a..b5077617aa 100644 --- a/dom/webidl/AbortSignal.webidl +++ b/dom/webidl/AbortSignal.webidl @@ -8,6 +8,8 @@ Func="AbortController::IsEnabled"] interface AbortSignal : EventTarget { [NewObject] static AbortSignal abort(); + [NewObject] static AbortSignal timeout(unsigned long long milliseconds); + readonly attribute boolean aborted; attribute EventHandler onabort;