azure - 如何保护 Azure Blob 存储 URL 不被任何使用开发人员工具的人检索

标签 azure url html5-video blob azure-blob-storage

我必须将图像/视频保存在 azure 的 blob 中,然后在我的网站中使用它们。经过一些研究后,我发现您必须在 href 标记中包含 blob url,才能从 azure 检索图像/视频。

但是任何人都可以打开该网站页面并获取该 blob url 并滥用它。此外,该网站具有用户身份验证,因此只有在登录后,用户才能在网站页面上看到该图像/视频。

还有其他方法可以从 azure 中检索 blob 吗?或者有任何其他解决方案可以在开发人员工具中公开显示 url?

我目前正在使用带有 Visual Studio 的 azure 模拟器。

An example of a test site which is showing a video stored as a blob

最佳答案

我重新创建了一个 Azure Function 来实现我提到的第一个场景。存储帐户内的 Blob URL 未公开,并且容器及其中的所有内容都设置为私有(private)。由于我不知道您的身份验证方案,因此我暂时跳过了该方案,但您可以通过多种方式来确保这一点。

此代码中有一些快捷方式,但您将了解总体思路。代码如下:

public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "files/{id}")]
    HttpRequest req, string id, TraceWriter log)
{
    var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
    var client = account.CreateCloudBlobClient();
    var container = client.GetContainerReference("sitecontent");
    var blob = container.GetBlockBlobReference(id);

    var stream = new MemoryStream();
    await blob.DownloadToStreamAsync(stream);
    stream.Seek(0, SeekOrigin.Begin);

    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
    result.Content = new StreamContent(stream);
    result.Content.Headers.ContentType =
            new MediaTypeHeaderValue("application/octet-stream");

    return result;
}

我通过从 HTML 文件引用它来测试它,如下所示:

<img src="http://localhost:7071/api/files/techdays2017.jpg" alt="Me at TechDays 2017" />

我使用的镜像大小为267KB,使用存储模拟器进行本地测试时,函数的响应时间均小于200毫秒。

关于azure - 如何保护 Azure Blob 存储 URL 不被任何使用开发人员工具的人检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50507959/

相关文章:

node.js - Node 要监听azure ubuntu vm的端口/IP地址

python - Django:在此服务器上找不到请求的 URL/accounts/login/

html - 使用 HTML5 获取 API 允许访问控制允许来源 header

Android HTML5 视频 - 单击播放时有效,但不是 video.play()

azure - 有没有办法使用 Bicep 获取在 Azure SQL Server 防火墙中配置的多个不相关的 IP 地址?

powershell - 无法从 terraform 在 azure VM 中执行自定义数据

azure - AADB2C90083 : The request is missing required parameter: grant_type

javascript - 在我的框架中查找带有函数的页面网址

javascript - HTML5 视频无法在任何浏览器中运行

android - 在 webview 中获取 html5 视频海报