Sitelet https://github.com/Netis/cloud-probe/issues/237
Skip to content

[cpdaemon] Worker config decoding is too lenient (case-insensitive keys, zero-filled missing fields) #237

Description

@vaderyang

Environment

  • CP version: v0.9.4 (f925e5f6); Go 1.27

Description

cpdaemon/cpm decode the worker config with Go encoding/json. encoding/json matches struct field names case-insensitively (see the json:"..." tags in cpdaemon/pkg/worker/config.go:23-60) and leaves missing fields at their zero value without necessarily failing.

As a result, typos such as snAplen / sNaplen, or omitted required sections, can be silently accepted and the task starts with defaults, which is hard to diagnose.

Steps to reproduce

  1. Write snaplen as snAplen.
  2. It still parses (falls back to the default), with no warning.

Expected

Match field names strictly; report a clear error for missing required fields.

Please confirm

Is this leniency intentional, or can it be tightened?


中文原文

测试环境

  • CP 版本:v0.9.4(f925e5f6);Go 1.27

问题描述

cpdaemon/cpm 用 Go encoding/json 解码 worker 配置。encoding/json 对结构体字段名是大小写不敏感匹配的(见 cpdaemon/pkg/worker/config.go:23-60 的 json:"..." 标签),且缺失字段保留零值、不一定报错。

结果:snAplen / sNaplen 这类拼写错误、漏写必填段,都可能被静默接受并用默认值起 task,排障困难。

重现方法

  1. 把 snaplen 写成 snAplen;
  2. 观察仍能解析(落到默认值),无告警。

期望

严格匹配字段名;缺失必填字段给出明确错误。

请确认

这是刻意的宽容,还是可以收紧?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions