Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion www/components/ClientResumeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function ClientResumeButton({ username }: { username: string }) {
const [isLoading, setIsLoading] = useState(false);

const handleDownload = async () => {
const newWindow = window.open("", "_blank");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Good use of opening a blank window first to work around popup blockers!

For enhanced security and to follow best practices, when using window.open("", "_blank"), it's recommended to include "noopener,noreferrer" as the third argument (window features).

  • noopener: Prevents the new window from having access to window.opener, which mitigates potential tabnabbing attacks.
  • noreferrer: Prevents the browser from sending the Referer HTTP header to the new page.

While the immediate navigation is to a blob: URL, adopting this practice consistently is beneficial. What are your thoughts on applying this here?

    const newWindow = window.open("", "_blank", "noopener,noreferrer");

try {
setIsLoading(true);
const response = await fetch(`/api/resume?username=${username}`);
Expand All @@ -22,9 +23,14 @@ export default function ClientResumeButton({ username }: { username: string }) {

const blob = await response.blob();
const url = URL.createObjectURL(blob);
window.open(url, "_blank");
if (newWindow) {
newWindow.location.href = url;
} else {
window.open(url, "_blank");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the suggestion for the initial window.open call, it would be good to apply the "noopener,noreferrer" attributes to this fallback call as well. This ensures consistent security best practices even if the initial newWindow couldn't be opened and this fallback path is taken.

        window.open(url, "_blank", "noopener,noreferrer");

}
} catch (error) {
console.error("Error downloading resume:", error);
if (newWindow) newWindow.close();
} finally {
setIsLoading(false);
}
Expand Down
Loading