• expertmadman@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

    we’re working on a third party solution for this. Should have some updates that sandbox cargo builds shortly.

    https://github.com/phylum-dev/birdcage

    It’s a cross-platform sandbox that works on Linux via Landlock and macOS via Seatbelt. We’ve rolled this into our CLI (https://github.com/phylum-dev/cli) so you can do thinks like:

    phylum  
    

    For example for npm, which currently uses the sandbox:

    phylum npm install
    

    We’re adding this to cargo to similarly sandbox crate installations. Would love feedback and thoughts on our sandbox!

      • PlexSheep@feddit.de
        link
        fedilink
        arrow-up
        0
        ·
        10 months ago

        I don’t think this is a problem with proc macros or package managers. This is just a regular supply chain attack, no?

        The way I understand it, sandboxing would be detrimental to code performance. Imagine coding a messaging system with a serve struct, only for serde code to be much slower due to sandboxing. For release version it could be suggested to disable sandboxingy but then we would have gained practically nothing.

        In security terms, being prepared for incidents is most often better than trying to prevent them. I think this applies here too, and cargo helps here. It can automatically update your packages, which can be used to patch attacks like this out.

        If you think I’m wrong, please don’t hesitate to tell me!

    • Quexotic@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      10 months ago

      A Rust procedural macro (proc macro) is a metaprogramming feature in Rust that allows you to define custom syntax extensions and code transformations. They operate on the abstract syntax tree (AST) of Rust code during compilation and can generate or modify code based on annotations or custom syntax.

      Sandboxing a Rust proc macro refers to restricting the capabilities of the macro to improve security and prevent potentially harmful code execution. There are several reasons why someone might want to sandbox a proc macro:

      1. Security: Untrusted code can be executed during the macro expansion process. To prevent malicious code execution or code that could access sensitive information, sandboxing techniques are employed.

      2. Preventing unintended side effects: Some proc macros might inadvertently introduce side effects like file I/O or network requests. Sandboxing can limit these actions to ensure the macro only performs intended transformations.

      3. Resource control: To manage system resources, a sandboxed proc macro can be configured to run within resource limits, preventing excessive memory or CPU usage.

      4. Isolation: Sandboxing helps keep the macro’s execution isolated from the rest of the compilation process, reducing the risk of interfering with other parts of the code.

      Sandboxing a Rust proc macro typically involves using crates like sandbox or cap-std to restrict the macro’s capabilities and limit its access to the system. This ensures that the macro operates within a controlled environment, enhancing the overall safety of code compilation and execution.

      -GPT

      I didn’t get it either.

      Seems to me if your code will be this unpredictable, you should only run it on an air gapped machine

      • astarob@sh.itjust.works
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        10 months ago

        It’s just compile time code execution.

        The difference between those macros („procedural macros“) and regular macros is that while regular macros are pretty much only templated code that is unfolded, proc macros contain code that is run at compile time, so they are more powerful but also more dangerous from a security perspective as you would expect just compiling a program to be safe.

        Also: is copy pasting ChatGPT answers a thing now even when you, as you said, don’t even know what it means??