Safari already contains some basic mitigations to prevent XSS (cross-site scripting). The ability to perform these attacks do not represent a flaw in the browser but is due to vulnerabilities in web applications that allow malicious scripts to be run by the browser so they are difficult to prevent from the client-side software.
In many instances, XSS attacks are used to deliver payloads that would require privilege escalation exploit or authentication by user to install. When a payload is delivered, the security mitigations within the OS prevent installation.
In other instances, XSS attacks are used to steal authentication cookies to hijack web application sessions. To perform this type of attack, the attacker must a) embed the script in the webpage, b) send users a malicious url with embedded scripts that links to the vulnerable webpage, or c) inject scripts into the communication between client/server using MITM.
a) Embedding a script into a webpage is easy on webpages where users can post information to be viewed by others, such as on social networking sites. This would allow the theft of the cookies related to that specific site regardless of encryption. Ads on websites can be used in a similar manner. On encrypted connections, the lock icon may not appear or may indicate that insecure elements exist on the page in some instances of this type of XSS attack so manually verifying the digital certificate before logging in is important. This is a good example as to why different passwords should be used for security sensitive sites.
Embedding a script directly into the encrypted login webpage of websites where users can not post data is much more difficult. Banking websites typically have this type of login. This would require the compromise of the server hosting the webpage so that the webpage content could be modified.
b) Malicious urls with embedded scripts could be used to deploy an XSS attack on security sensitive logins, such as the logins for banks, if the webpage contains an XSS vulnerability. Again, the lock icon may indicate insecure elements exist on the webpage. The best practice to avoid this type of attack is to never login to security sensitive webpages from links in emails, email attachments, or instant messages even if the credentials for the webpage appear to be safe.
c) Make sure that the network you are using is secure. Do not login to security sensitive webpages on networks with unknown/untrusted users and use a utility to detect MITM attacks.