Automating Google Drive Public Link Expiration: A Google Workspace Insight

Automated security for shared Google Drive files.
Automated security for shared Google Drive files.

Automating Google Drive Public Link Expiration: A Critical Google Workspace Insight

Managing file sharing permissions in Google Drive is a crucial aspect of data security, especially within a Google Workspace environment. A common challenge faced by administrators and users alike is the need to temporarily share files with "Anyone with the link" access, only to have those links automatically revert to a more restricted state after a set period. One user recently brought this exact need to the Google support forum, asking for a way to automate the restriction of publicly shared files after 30 days across their entire workspace.

The Challenge: No Native "Anyone with the Link" Expiration

The core of the user's query highlights a gap in Google Drive's native sharing features. While Google Drive offers a "Set Expiration" feature, it's designed to work specifically when sharing files with named individuals or groups. Unfortunately, it does not currently support automatically expiring "Anyone with the link" public access. This means that once a file is shared publicly, it remains publicly accessible until an administrator or owner manually intervenes.

For organizations striving for robust data governance and looking to improve their google workspace reports on sharing practices, this manual oversight can be a significant hurdle. It introduces potential security risks if public links are forgotten or not regularly audited.

Solutions for Automating Public Link Restrictions

While a direct setting in the Google Admin console for this specific automation doesn't exist, experts in the forum thread pointed to two primary methods for achieving this critical security control:

  • Google Apps Script / GAM: This is a powerful, flexible solution for Google Workspace administrators. By leveraging the Google Drive API, you can write custom scripts that scan for publicly shared files and programmatically modify their permissions after a defined period. This method offers high customization and integrates directly with your Google Workspace infrastructure.
  • Third-Party Security and Management Tools: Several enterprise-grade tools, such as BetterCloud or GAT+, offer advanced policy enforcement capabilities. These platforms often include features to automatically audit and manage public sharing links, allowing administrators to set policies for automatic restriction or removal after a specified duration. These tools can significantly enhance your ability to generate comprehensive google workspace reports on sharing compliance.

Implementing Automation with Google Apps Script

For those comfortable with scripting, Google Apps Script provides a cost-effective and direct way to implement this automation. One expert provided a helpful example script. Since Google Drive doesn't explicitly track a "date shared" for public links, this script intelligently uses the "Last Updated" date as a proxy. If a file with a public link hasn't been modified in 30 days, the script assumes it might be stale and removes its public access.

Example Google Apps Script to Remove Old Public Links:

function removeOldPublicLinks() {
  var thirtyDaysAgo = new Date();
  thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);

  var files = DriveApp.searchFiles('visibility = "anyoneWithLink"');

  while (files.hasNext()) {
    var file = files.next();
    if (file.getLastUpdated() < thirtyDaysAgo) {
      file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.NONE);
    }
  }
}

Quick Steps to Run the Script:

  1. Navigate to script.google.com and start a new project.
  2. Paste the provided code into the editor.
  3. Important Advice: Before deploying this script across your entire workspace, thoroughly test it on a dummy folder with non-critical files. This precaution prevents accidental unsharing of active, important documents.

Enhancing Your Workspace Security

Automating the restriction of public Google Drive links is a vital step towards bolstering your organization's data security posture. Whether through custom scripts or third-party tools, implementing such policies ensures that sensitive data isn't inadvertently exposed indefinitely. We encourage administrators to explore these solutions and also to provide feedback to Google through the help & feedback route, advocating for native "Anyone with the link" expiration features in future Google Workspace updates. This kind of proactive management directly contributes to better security google workspace stats and overall compliance.

Google Apps Script for Drive administration.
Google Apps Script for Drive administration.

Uncover dozens of insights

from Google Workspace usage to elevate your performance reviews, in just a few clicks

 Sign Up for Free TrialRequires Google Workspace Admin Permission
Live Demo
Workalizer Screenshot