PyPI发布GitHub Action存在可注入表达式扩展漏洞

本文详细分析了PyPI发布GitHub Action中存在的安全漏洞,该漏洞由于在操作步骤中使用了可注入的表达式扩展,可能导致攻击者在特定条件下执行任意代码。漏洞影响版本低于1.13.0,已在新版本中修复。

PyPI发布GitHub Action存在可注入表达式扩展漏洞

漏洞详情

摘要

gh-action-pypi-publish在可能被攻击者控制的上下文中使用了GitHub Actions表达式扩展(即${{ ... }})。根据调用gh-action-pypi-publish的触发器类型,这可能允许攻击者在调用gh-action-pypi-publish的工作流程步骤中执行任意代码。

详细信息

gh-action-pypi-publish包含一个复合操作步骤set-repo-and-ref,该步骤使用了表达式扩展:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
- name: Set repo and ref from which to run Docker container action
  id: set-repo-and-ref
  run: |
    # Set repo and ref from which to run Docker container action
    # to handle cases in which `github.action_` context is not set

    REF=${{ env.ACTION_REF || env.PR_REF || github.ref_name }}
    REPO=${{ env.ACTION_REPO || env.PR_REPO || github.repository }}
    REPO_ID=${{ env.PR_REPO_ID || github.repository_id }}
    echo "ref=$REF" >>"$GITHUB_OUTPUT"
    echo "repo=$REPO" >>"$GITHUB_OUTPUT"
    echo "repo-id=$REPO_ID" >>"$GITHUB_OUTPUT"
  shell: bash
  env:
    ACTION_REF: ${{ github.action_ref }}
    ACTION_REPO: ${{ github.action_repository }}
    PR_REF: ${{ github.event.pull_request.head.ref }}
    PR_REPO: ${{ github.event.pull_request.head.repo.full_name }}
    PR_REPO_ID: ${{ github.event.pull_request.base.repo.id }}

在正常的预期操作中,这些扩展用于为refrepo-id等输出建立正确的优先级。

然而,这些扩展有一个副作用:因为它们使用${{ ... }}而不是${...}(即普通的shell插值),它们可以绕过正常的shell引用规则。特别是,如果env.ACTION_REFenv.PR_REF都计算为空字符串,那么表达式将回退到github.ref_name,这可能是攻击者通过分支或标签名称控制的字符串。

例如,如果攻击者能够将分支名称设置为类似innocent;cat${IFS}/etc/passwd的内容,那么REF行可能会扩展为:

1
REF=innocent;cat${IFS}/etc/passwd

这将把REF设置为innocent,然后运行攻击者的代码。

影响

此漏洞的影响非常低:在正常操作中,相关表达式不太可能被评估,因为env.ACTION_REF应该始终优先。

特别是,在许多流行配置中该操作不易受攻击,例如使用pull_requestreleasepush: tags事件调用操作的情况。

技术信息

受影响版本:< 1.13.0 修复版本:1.13.0

漏洞类型:命令注入(CWE-77) 严重程度:低 CVSS评分:0.0

参考信息

  • GHSA-vxmw-7h4f-hqxh
  • pypa/gh-action-pypi-publish@77db1b7
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计