mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
LibWeb: Implement basic high resolution time coarsening
Several interfaces that return a high resolution time require that time to be coarsened, in order to prevent timing attacks. This implementation simply reduces the resolution of the returned timestamp to the minimum values given in the specification. Further work may be needed to make our implementation more robust to the kind of attacks that this mechanism is designed to prevent.
This commit is contained in:
committed by
Alexander Kalenik
parent
a5be7cb6fb
commit
39445d6dd6
Notes:
github-actions[bot]
2025-01-30 17:39:14 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/39445d6dd68 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3381 Reviewed-by: https://github.com/AtkinsSJ ✅
@@ -5,6 +5,14 @@
|
||||
bufferedMessages.push(message);
|
||||
}
|
||||
|
||||
function synchronousWaitMicroseconds(microseconds) {
|
||||
var start = performance.now() * 1000,
|
||||
now = start;
|
||||
while (now - start < microseconds) {
|
||||
now = performance.now() * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
const globalObserver = new PerformanceObserver((list, observer) => {
|
||||
printlnBuffered(`observer === globalObserver: ${observer === globalObserver}`);
|
||||
printlnBuffered(
|
||||
@@ -53,7 +61,11 @@
|
||||
globalObserver.observe({ entryTypes: ["measure", "mark"] });
|
||||
|
||||
const startMark = performance.mark("start");
|
||||
// The resolution of the clock used by the Performance interface is 100 microseconds, so we wait twice that time
|
||||
// between calls to ensure they are ordered as we expect.
|
||||
synchronousWaitMicroseconds(200);
|
||||
const endMark = performance.mark("end");
|
||||
synchronousWaitMicroseconds(200);
|
||||
const measureMark = performance.measure("measure", "start", "end");
|
||||
|
||||
function printCatchedException(func) {
|
||||
|
||||
Reference in New Issue
Block a user