TextEdit slams quarantine on edited scripts on save

Number:rdar://FB9767125 Date Originated:2021-11-18
Status:Open Resolved:
Product:AppKit Product Version:macOS 12.0.1
Classification: Reproducible:Always
Have an executable script. e.g. `ls.sh`

Verify that is is executable in bash.
> ls.sh

Open it with TextEdcit
Insert a newline

Try to run it in Terminal again:
> ls.sh
zsh: operation not permitted: ./ls.sh

Note that TextEdit has slammed a quarantine attribute on it
> xattr -l ls.sh
com.apple.TextEncoding: utf-8;134217984
com.apple.lastuseddate#PS: ??a
com.apple.metadata:_kMDItemUserTags: bplist00?
com.apple.quarantine: 0086;619612f1;TextEdit;

Although TextEdit does have the 

entitlement, allowing exectuables to be openend and edited.

Side Note: 
If you dont' use the NSDocument based safe write routines, but just open that file directly and replace its contents evertyhing is fine. Which is a shame, so this isn't a security feature to not alow editing of scripts, it is just a bug when using the NSDocument based writing routines adding quarantine on overwrite too.

This was a problem for SubEthaEdit as it was using NSDocument based methods, now it uses the less "safe" just overwrite in place methods to work around this. which is unfortunate.

This behavior appeared in Monterey 12.0.1 for us. Big Sur does not have this.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!