【问题标题】:Apostrophe CMS - Protecting Static ContentApostrophe CMS - 保护静态内容
【发布时间】:2020-01-03 21:23:36
【问题描述】:

我现在正在使用撇号 cms,并已使用撇号-Saml 将整个应用程序置于 SAML IDP 后面。但是,我注意到用户上传的文件被放置在“公共”目录中,无需登录即可查看。有没有一种方法可以在身份验证后保护上传的图像/视频/文件?

撇号-express 模块有一个中间件选项,但在访问静态内容时似乎没有使用它。

我的下一个尝试是重写撇号资产方法

self.servePublicAssets = function() {
  var middleware = [];
  if (self.lessMiddleware) {
    // bc: only if the new implementation of enableLessMiddleware is in place.
    // If it's an old override, it'll already be added to Express and
    // this property won't be set
    middleware.push(self.lessMiddleware);
  }


  //THIS NEXT LINE IS THE LINE OF INTEREST
  middleware.push(self.apos.express.static(self.apos.rootDir + '/public'));
  //SEE THE LINE ABOVE


  self.expressMiddleware = {
    // Run really early, before all of the stuff apostrophe-express normally
    // puts in, for performance reasons. Preempts expensive
    // queries related to `apostrophe-global` on every static file
    when: 'beforeRequired',
    middleware: middleware
  };
};

我基本上试图将“兴趣线”换成如下所示的内容:

middleware.push(self.apos.app.use(self.apos.rootDir + '/public', authMethod(), self.apos.express.static(self.apos.rootDir + '/public')));

但这似乎也不起作用。有没有人有任何想法或确切知道如何做到这一点?谢谢。

【问题讨论】:

  • 您的总体方向是正确的,但 Apostrophe 中尚不存在此功能。我已经用最新的更新了为您跟踪它的票证,因为附件现在保留了它们出现的docIds 数组,因此有可能做您想做的事,根据以下内容正确检查撇号权限这些文件:github.com/apostrophecms/apostrophe/issues/853 尽管在您的情况下,我认为您只想将其限制为“您已登录”,而不是比这更严格。你的authMethod 是否被调用了?
  • 感谢汤姆的回复。 authMethod 似乎没有被调用。上面提到的更改只是超时并给出了堆溢出错误。有什么想法吗?我会看看你提到的问题
  • 老实说不知道为什么会这样。我们可能会在某个时候为有需要的内部客户实施此功能,或者等待企业客户支持实施。

标签: node.js express apostrophe-cms


【解决方案1】:

虽然在提出问题时很困难,但现在很简单:安装和配置 apostrophe-secure-attachments 模块。

【讨论】:

    猜你喜欢
    • 2011-02-26
    • 1970-01-01
    • 2017-03-08
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    • 2018-12-03
    • 1970-01-01
    相关资源
    最近更新 更多