Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ActiveTK/cdb580e07a8d2e169ccaa631c3349a90 to your computer and use it in GitHub Desktop.

Select an option

Save ActiveTK/cdb580e07a8d2e169ccaa631c3349a90 to your computer and use it in GitHub Desktop.
/*!
* リクエストURIの最大長からブラウザを判定するスクリプト
* (c) 2024 ActiveTK. / 2024/03/17
* PoC: https://www.activetk.jp/public/browser_max_reqline.html
*/
const fetch_host = "https://no-such-a-doma.in/?browser_max_reqline=";
const Chrome_Max_Length = 2097152 - fetch_host.length;
const Firefox_Max_Length = 1048572 - fetch_host.length;
async function try_fetch(url) {
try {
const response = await fetch(url);
const data = await response.text();
return "Success";
} catch (error) {
return error;
}
}
async function is_fetchable(len) {
let start_performance = performance.now();
try {
let repeat_data = "a".repeat(len);
let fetch_result = await try_fetch(fetch_host + repeat_data);
if (
// Request Done (unexpected)
fetch_result == "Success" ||
// CORS Error (firefox)
fetch_result == "TypeError: NetworkError when attempting to fetch resource."
) {
return true;
}
} catch (e) {}
let time_taken = performance.now() - start_performance;
if (time_taken > 300) {
// Lookup Failed
return true;
} else {
// RequestLine Too long
return false;
}
}
(async () => {
let Firefox_Max_Length_= await is_fetchable(Firefox_Max_Length);
let Firefox_Max_Length_plus_one = await is_fetchable(Firefox_Max_Length + 1);
console.clear();
console.log(
"%cFirefox_Max_Length[" + Firefox_Max_Length + "]: " +
Firefox_Max_Length_, "font-size:2rem;"
);
console.log(
"%cFirefox_Max_Length+1[" + (Firefox_Max_Length + 1) + "]: " +
Firefox_Max_Length_plus_one, "font-size:2rem;"
);
let Chrome_Max_Length_ = await is_fetchable(Chrome_Max_Length);
let Chrome_Max_Length_plus_one = await is_fetchable(Chrome_Max_Length + 1);
console.log(
"%cChrome_Max_Length[" + Chrome_Max_Length + "]: " +
Chrome_Max_Length_, "font-size:2rem;"
);
console.log(
"%cChrome_Max_Length+1[" + (Chrome_Max_Length + 1) + "]: " +
Chrome_Max_Length_plus_one, "font-size:2rem;"
);
let browser_name = "Unknown";
if (Chrome_Max_Length_ && !Chrome_Max_Length_plus_one)
browser_name = "Google Chrome";
else if (Firefox_Max_Length_ && !Firefox_Max_Length_plus_one)
browser_name = "Firefox";
console.log(
"%cブラウザ判定結果%c 汝のブラウザは %c" + browser_name + "%c に違いない!!",
"font-size:2rem;color:white; background-color:purple; padding:2px; border-radius:4px;",
"font-size:2rem;",
"font-size:2rem;color:green;",
"font-size:2rem;"
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment