Repository navigation
Description
I want to have AI build/update some Safari Extensions!
Unfortunately, all legacy Safari Extensions (.safariextz format) need to be signed by an official Safari Developer certificate issued by Apple. Apple no longer issues these certificates.
We can create and install a self-signed Safari Developer certificate like this:
#!/bin/bash
set -e
export RANDFILE=/dev/null
ID=$(LC_ALL=C tr -dc A-Z0-9 </dev/urandom | head -c 10)
read -rp "Email: " EMAIL
NAME="Safari Developer: ($ID) $EMAIL"
cat >safari-cert.conf <<EOF
[req]
prompt=no
distinguished_name=name
x509_extensions=extensions
[name]
CN=$NAME
[extensions]
basicConstraints=critical,CA:false
keyUsage=critical,digitalSignature
extendedKeyUsage=1.2.840.113635.100.4.8
1.2.840.113635.100.6.1.5=critical,DER:05:00
EOF
openssl req -new -x509 -nodes -newkey rsa:2048 -sha256 -days 3650 -config safari-cert.conf -keyout safari.key -out safari.crt
openssl pkcs12 -export -inkey safari.key -in safari.crt -name "$NAME" -passout pass:safari -out safari.p12
KEYCHAIN="$HOME/Library/Keychains/login.keychain"
security import safari.p12 -k "$KEYCHAIN" -P safari -T /Applications/Safari.app
security add-trusted-cert -r trustRoot -k "$KEYCHAIN" safari.crt
rm safari-cert.conf safari.crt safari.key safari.p12
echo "Installed $NAME"
This will initially appear to satisfy the Extension Builder (Develop → Show Extension Builder within Safari), but you'll get an error when you try to actually install an extension, or the .safariextz the builder generates.
To get passed that, we need to patch Safari. Run this while Safari is open. The app will be patched in memory and the change will only persist until Safari is restarted:
#!/bin/bash
set -e
PID=${1:-$(pgrep -x Safari)}
SYMBOL="_ZNK6Safari11Certificate31hasInvalidAppleCertificateChainEdPKS0_"
[ -n "$PID" ] || { echo "Safari is not running." >&2; exit 1; }
ADDRESS=$(
lldb -p "$PID" \
-o "disassemble -n $SYMBOL -c 1" \
-o detach -o quit 2>&1 |
sed -n "s/^[[:space:]]*\(0x[0-9a-f]*\):.*/\1/p" |
head -n 1
)
[ -n "$ADDRESS" ] || { echo "Could not find Safari verifier." >&2; exit 1; }
lldb -p "$PID" \
-o "memory write $ADDRESS 0x31 0xc0 0xc3" \
-o "memory read --format x --size 1 --count 3 $ADDRESS" \
-o detach -o quit
echo "Safari PID $PID patched in memory at $ADDRESS."
(FYI, both scripts were written by the new GPT 5.6 Sol, with some manual cleanup. I think it did well? My sense is that it's great at coding, but it's not knowledgable like Claude, it needs to be told things explicitly. It doesn't seem to mind reverse engineering work though.)
Once an extension has been installed, it will continue working without the patch. But I don't like this as a long term solution.
What is the least bad thing to do here? Certainly, it should be easy to apply the memory patch to the on-disk Safari framework. I'm annoyed because I have gone out of my way to avoid modifying Safari at all—I just think it's so cool that we can update the framework and use the vanilla app.
But, clearly something has to be done here.
Activity
Wowfunhappy commentedon Jul 11, 2026
@krackers If you have thoughts on how to architect this, I'd enjoy hearing them.
Although, I do think the best, practical fix is probably to suck it up and patch the framework on disk. (Or to create and use some heretofore unmade auto-patcher that doesn't break code signatures, I guess.)
Although although, it would be cool if we could exploit the fact that once an extension is installed, it stays installed. From that perspective, the thing with lldb actually works fine, I guess? But long term I'd like users to not need the developer tools installed.
Although although although, if we're talking long term, I'm probably going to try again at recompiling Security.framework (with AI assistance this time, unlike six years ago), at which point I could probably just patch the extension check there.
Wowfunhappy commentedon Jul 11, 2026
Oh, GPT also thinks the patch could just be done within WebKit... although it's apparently not allowed to tell me how to do it.
I'm confused because I would have thought they'd be in different address spaces? But I guess because Safari loads the framework, the framework has access to Safari's address space, or something like that?
Wowfunhappy commentedon Jul 11, 2026
Apparently arguing with the classifier works? It gave me this sample code:
krackers commentedon Jul 11, 2026
I had no idea these existed! Thought a self-signed one would be enough...
That would fit with rumors that Claude is a much larger pretrain (rumors that it might not even be sparse MoE but idk if that's credible).
Since the patch is to the main safari process, why can't you just have a SIMBL plugin? You aren't limited to doing obj-c swizzling, once you're injected into the process you can do anything you want, e.g. write arbitrary memory.
krackers commentedon Jul 11, 2026
Yup that code looks right. Don't add this to webkit, that's insane. Just have it as a simbl plugin.
Wowfunhappy commentedon Jul 11, 2026
Why don't you like having this in WebKit?
I might be overindexing on this, but I'm concerned about the Mavericks Forever setup path, which has people install a web browser well before SIMBL, because a browser is the most essential thing everyone needs. So the "Allow self-signed extensions" SIMBL plugin would be much further down the page, and not everyone would install it.
Which, like, is fine—I want users to be in control. But in this case, it is literally impossible for anyone to sign an extension properly, and it has been impossible for 6+ years (I don't remember exactly when the Safari Developer program was shut down).
With a SIMBL plugin, any time that I or anyone else distributes an extension, it's going to have a "needs modern WebKit and SIMBL and the self-signed extensions SIMBL plugin" asterisks attached. I'd like to be able to distribute extensions and have them work for anyone with modern WebKit installed.
krackers commentedon Jul 11, 2026
In-memory patching of a process from a loaded framework just feels really gross.
I mean it's not what you would expect. If I saw that the in-memory signature of the code segment differed from the on-disk one, especially in a browser, I'd immediately be supsicious and wonder if i'd been exploited.
If you keep it as a SIMBL plugin, then it's more obvious what's going on.
krackers commentedon Jul 11, 2026
also can you ask chatgpt to double check that there's really no bypass (e.g. no hidden default or anything) which allows you to bypass the signature check? I've always wondered that Apple must have had a way to bypass it during development, similar to how chrome allows a developer mode
Wowfunhappy commentedon Jul 11, 2026
Oh, believe me I did! It says nothing exists and that this byte patch is the cleanest way. (I admittedly didn't try with Claude; I'm really trying to conserve my usage while Fable works through larger and thornier WebKit problems.)
krackers commentedon Jul 11, 2026
If you have time to burn, I double checked and similar to firefox you can temporarily install unsigned extensions until quit by using developer menu > extension builder> plus button at bottom.
I wonder how this mechanism, if it's purely in-memory I guess there's not much that can be done.
Wowfunhappy commentedon Jul 11, 2026
Huh? I can add them to the list in Extension Builder, but not install them. Merely having them in the list doesn't do anything, Safari can't use them. What am I missing?
krackers commentedon Jul 11, 2026
Nvmind you're right, I had tested on a newer non-mavericks safari and then assumed same was true on 10.9 since I saw the same menu. Serves me right for not actually checking.
Remove the "#54 broken-main-thread-identity" hack family (7 falsified…
Divergence cleanup: remove vestigial band-aids whose root cause is al…
11 remaining items
krackers commentedon Aug 12, 2026
This was with opus 5? Based on how many fundamental conceptual mistakes it has made, it seems the anecdotal reports that it's too RL fried or something seems right.
In any case, you can verify it by connecting lldb and dumping the relevant memory page. Lookup the image base address
image list, calculate the symbol address, thendi -fand inspect the actual memory (orimage dumparound that, if you're so inclined).That said I don't know if code signing somehow plays a role here, maybe there's some security feature where if the binary is signed then it trusts that pages won't be modified in memory so it does this optimization. Or it deliberately ejects the page with invalid signature and reloads from disk. (after all it is a browser, and this seems like a good feature to protect against such memory overwrite shenanigans)
Maybe you should switch to kimi k3 or deepseek for this work? It doesn't really require that frontier a model.
Wowfunhappy commentedon Aug 20, 2026
This message hasn't reappeared after a week of moving the patch outside of SIMBL (it's currently injected via Security.framework), so I'm now pretty sure SIMBL is messing this up somehow, even though that doesn't really make sense.
So my options are:
I think I'm going to just patch the Safari framework on disk.
Wowfunhappy commentedon Aug 20, 2026
FYI, to just patch Safari.framework:
Allow self-signed extensions:
perl -0777 -pi -e 's/\x55\x48\x89(\xe5\xe8\x15\xf8\xff\xff)/\x31\xc0\xc3$1/' /System/Library/PrivateFrameworks/Safari.framework/Versions/A/SafariUninstall patch
perl -0777 -pi -e 's/\x31\xc0\xc3(\xe5\xe8\x15\xf8\xff\xff)/\x55\x48\x89$1/' /System/Library/PrivateFrameworks/Safari.framework/Versions/A/SafariI don't know why, but seeing this in the form of a perl one-liner makes me feel better about it.
krackers commentedon Aug 21, 2026
Darn how puzzling. Is it possible that it's not just Safari.app itself which uses the framework but some other binary which also loads it? When you're injecting your patch in Security.framework are you gating by the process name? What happens if you gate it like that to only Safari?
Fwiw I still really suspect it's just the SIMBL raciness manifesting. Isn't the fact that you observed
evidence of that? Say SIMBL racily fails to inject into Safari. Then you won't notice it until it randomly decides to recheck signature, which could be days down the line.
Patching safari.framework on disk seems fine for now. I like the perl 1-liner. I'd also just drop a README.txt though so someone who discovers the signature mismatch years down the line remembers why the thing has been tampered with.
Wowfunhappy commentedon Aug 21, 2026
But then none of my other SIMBL plugins should be working either, right? Notably, this means I would see a full screen button in the upper right corner of the window, which I would notice quickly (speaking from experience).
Mind, at this point I also think this is caused by some sort of SIMBL raciness, but I can't come up with a theory for why that would happen.
(I didn't miss your other questions but I'm too tired to look now.)
krackers commentedon Aug 21, 2026
No? Some plugins can be loaded at any time and they work fine. As an example, swizzling some method of NSWindow can be done arbitrarily late and the side-effects will always show up on the next paint (more or less I think, so long as you can trigger a full redraw). By comparison when you do memory rewriting within a SIMBL plugin, you're relying on the fact that you must rewrite the memory before the function you're rewriting is first run.
Or if that wasn't clear:
If Safari runs signature validation at t1, and your bundle which rewrites the function gets loaded at t2 > t1, then it's too late.
But if Safari draws the NSWindow at t1, your bundle which removes full screen at t2 loads at t2 > t1, then the NSWindow is drawn again at t3, you still see the buttom removed. Technically there is a brief instant between [t1, t3] where the button does exist but so long as this is < 16ms it's never practically drawn.
Wowfunhappy commentedon Aug 21, 2026
But it doesn't really make sense for Safari to be checking the certificate so early when it doesn't complain until much later. And I know that at least in the extension-install case, the patch can be installed arbitrarily late via lldb.
But whatever, as I said you must be right somehow since it's not working.
krackers commentedon Aug 21, 2026
Who knows maybe it's some grace period or something. I think the easiest way to test this theory would be to code-inject via DYLD_INSERT_LIBRARIES into safari, and do memory rewriting from there? That would guarantee you get early but also still maintain in-memory rewriting.
Wowfunhappy commentedon Aug 22, 2026
It will be an option in the installer.
Closing this since shape of solution has been decided and I'm happy with it.
Wowfunhappy commentedon Aug 25, 2026
...probably should have double checked that the perl one-liner actually worked before declaring victory. Oops. Safari won't open unless the Safari.framework binary is codesigned. I forgot about that.
So I can do:
This works fine, it's just (A) no longer a clean Perl one-liner (B) requires the developer Command Line Tools and (C) can't just be cleanly reversed with a second perl command.
To resolve
B, the installer will need to shipjtool2. Then I think the syntax is just./jtool2 --sign --inplace /System/Library/PrivateFrameworks/Safari.framework/Versions/A/SafariTo resolve
C, the installer will need to actually keep a backup of the original somewhere. Presumably it'll just be beside the patched binary.None of this is hard, it just slightly complicates something that I'd really wanted to keep simple. Oh well.
...I guess the alternative to both would be to pre-sign the patched framework, then have the installer apply a tiny
bspatchon both install and uninstall. Paradoxically, this feels at once more elegant but also overcomplicated, and potentially looks more sketchy.Wowfunhappy commentedon Aug 30, 2026
Okay, this can still be done as perl one-liners, you just need two of them.
Install:
Note that the code signature is still there, we just removed the load command. That means to uninstall, we can do:
Ta-da, back to the normal, signed binary. No developer tools needed, no separate backups, we're just changing a handful of bytes. I'm happy.
P.S. Here is a Perl script (written by GPT 5.6 Sol) which will generate Perl-one-liners to remove and restore the code signature of a macho binary.
Details