安全执行不受信任的 Haskell 代码

发布于 2024-11-06 20:01:19 字数 442 浏览 3 评论 0原文

我正在寻找一种安全运行任意 Haskell 代码(或拒绝运行不安全代码)的方法。

必须具备:

  • 模块/函数白名单
  • 执行超时
  • 内存使用限制

我希望看到的功能:

  • 杀死线程的能力
  • 将模块编译为本机代码
  • 缓存编译后的代码
  • 同时运行多个解释器
  • 针对编译器错误的复杂数据类型(在字符串中插入简单消息)

有了这种功能,就可以实现一个能够运行任意 Haskell 代码的浏览器插件,这就是我的想法。

编辑:我有两个答案,都很好。谢谢!可悲的是,似乎没有现成的库,只有类似的程序。不过,这是一个有用的资源。无论如何,我想我会等待 7.2.1 发布并尝试在我自己的程序中使用 SafeHaskell。

I'm looking for a way to run an arbitrary Haskell code safely (or refuse to run unsafe code).

Must have:

  • module/function whitelist
  • timeout on execution
  • memory usage restriction

Capabilities I would like to see:

  • ability to kill thread
  • compiling the modules to native code
  • caching of compiled code
  • running several interpreters concurrently
  • complex datatype for compiler errors (insted of simple message in String)

With that sort of functionality it would be possible to implement a browser plugin capable of running arbitrary Haskell code, which is the idea I have in mind.

EDIT: I've got two answers, both great. Thanks! The sad part is that there doesn't seem to be ready-to-go library, just a similar program. It's a useful resource though. Anyway I think I'll wait for 7.2.1 to be released and try to use SafeHaskell in my own program.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生活了然无味 2024-11-13 20:01:19

我们已经在 lambdabot 中这样做了大约 8 年,它支持:

  • 受控命名空间
  • 操作系统强制超时
  • 本机代码模块
  • 缓存
  • 并发交互式顶级
  • 自定义错误消息返回。

这一系列规则有文档记录,请参阅:

lambdabot 中采取的安全方法启发了 Safe Haskell 语言扩展工作。


有关在 Haskell 中动态扩展已编译 Haskell 应用程序的方法,请参阅两篇论文:

We've been doing this for about 8 years now in lambdabot, which supports:

  • a controlled namespace
  • OS-enforced timeouts
  • native code modules
  • caching
  • concurrent interactive top-levels
  • custom error message returns.

This series of rules is documented, see:

The approach to safety taken in lambdabot inspired the Safe Haskell language extension work.


For approaches to dynamic extension of compiled Haskell applications, in Haskell, see the two papers:

心如荒岛 2024-11-13 20:01:19

GHC 7.2.1 可能会有一个名为 SafeHaskell 的新工具,其中涵盖了一些内容你想要的。 SafeHaskell 确保类型安全(因此像 unsafePerformIO 这样的东西是非法的),并建立信任机制,以便可以信任具有安全 API 但使用不安全功能实现的库。它专为运行不受信任的代码而设计。

对于其他实际方面(超时等),正如 Don 所说,lambdabot 将是一个值得关注的好地方。

GHC 7.2.1 will likely have a new facility called SafeHaskell which covers some of what you want. SafeHaskell ensures type-safety (so things like unsafePerformIO are outlawed), and establishes a trust mechanism, so that a library with a safe API but implemented using unsafe features can be trusted. It is designed exactly for running untrusted code.

For the other practical aspects (timeouts and so on), lambdabot as Don says would be a great place to look.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文