Skip to content

Instantly share code, notes, and snippets.

View eligrey's full-sized avatar
:octocat:

Eli Grey eligrey

:octocat:
View GitHub Profile
@eligrey
eligrey / bypass-csp.js
Last active November 26, 2019 00:45
Universal CSP bypass exfiltration tool
// update: this was over-engineered
// just navigate to an HTTP 204 redirect to exfiltrate data
@eligrey
eligrey / filename from path regexes.js
Created August 16, 2019 03:19
filename from path regexes
const pathFileNameMatcher = /\/?(?<fileName>[^/]+(?<fileExtension>\.[^/.]*)?)\/*$/;
const pathFilePrefixMatcher = /\/?(?<filePrefix>[^/]+)(?<fileExtension>\.[^/.]*)?\/*$/;
'test/foo/|foo|.test.enc/'.match(pathFilePrefixMatcher).groups.filePrefix == '|foo|.test'
const matches = new URL('https://your-url-here/example.txt').pathname.match(pathFileNameMatcher);
const fileName =
(matches && matches.groups && matches.groups.fileName) || 'file';
@eligrey
eligrey / spreadify.once.js
Last active August 8, 2022 05:41
spreadify: add a universal iterator to any array-like object
/** Alternative spreadify implementation with `...spreadify.once` */
const spreadify = {
/** Always spread */
*[Symbol.iterator](): any {
delete this[Symbol.iterator];
yield* this.once[Symbol.iterator].call(this);
this[Symbol.iterator] = this.once[Symbol.iterator];
},
once: {
/** Spread once */
@eligrey
eligrey / hash.ts
Last active July 12, 2022 10:39
Simple cryptographic hashing function for ArrayBuffers in browsers
/**
* Get the cryptographic hash of an ArrayBuffer
*
* @param ab - ArrayBuffer to digest
* @param algorithm - Cryptographic hash digest algorithm
* @returns Hexadecimal hash digest string
*/
export const hash = async (
algorithm: string,
ab: ArrayBuffer | Promise<ArrayBuffer>,
@eligrey
eligrey / github-repo-exists.js.md
Last active January 5, 2024 07:10
GitHub private repository existence disclosure timing attack

eli submitted a report to GitHub.

Oct 1st, 2018

Description:

The X-Runtime-rack header leaks enough timing data to detect the existence of private repositories.

Steps To Reproduce:

@eligrey
eligrey / LICENSE.md
Last active February 22, 2023 13:08
Universal unsaved changes detector for tab close confirmation. No setup necessary!

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit

@eligrey
eligrey / LICENSE.md
Last active March 21, 2019 08:09
💬 Display an indicator favicon while there are any modified input fields. Try it out on https://eligrey.com

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit

Keybase proof

I hereby claim:

  • I am eligrey on github.
  • I am eligrey (https://keybase.io/eligrey) on keybase.
  • I have a public key whose fingerprint is EE63 3C20 BC4A 88A7 165C 917A 9022 A5E1 114E C7A3

To claim this, I am signing this object:

@eligrey
eligrey / document-body.js
Last active June 11, 2016 02:35
Workaround for Mozilla bug #1276438 in Firefox
// Workaround for Mozilla bug #1276438 in Firefox
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1276438
if (!Object.getOwnPropertyDescriptor(Document.prototype, "body"))
Object.defineProperty(Document.prototype, "body", {
enumerable: true
, configurable: true
, get() {
return this.evaluate(
"/*[local-name()='html'][namespace-uri()='http://www.w3.org/1999/xhtml']"
+ "/*[local-name()='body'][namespace-uri()='http://www.w3.org/1999/xhtml']"
@eligrey
eligrey / example.js
Last active December 7, 2023 16:38
Execute all scripts in a document. You'll need this if you're inserting external documents.
var doc = (new DOMParser).parseFromString("<html><script>alert(1)</script></html>", "text/html");
document.replaceChild(doc.documentElement, document.documentElement);
execute_scripts(); // alert(1)