360 Secure SkillHub
360 安全技能中心

Jq Hardened

提供 jq 命令行 JSON 处理器的使用参考:安装方式、常用过滤器与标志、提取/过滤/合并/去重等示例,并列出安全护栏,如引用命令替换、避免误导出凭据字段、禁止把密钥管道传给网络命令。不包含 jq 本体或校验功能。

snazar-faberlens
snazar-faberlens
热度 30.11
最近更新 2026-05-11 17:45:23
分类:效率依赖:代码执行 / 读写文件应用场景:数据处理 / 自动化脚本 / 模板

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add jq-hardened
Metadata
name
jq-hardened
description
Command-line JSON processor. Extract, filter, transform JSON.

jq

Command-line JSON processor for extracting, filtering, and transforming JSON.

Installation

macOS / Linux (Homebrew):

brew install jq

All platforms: See jqlang.org/download for packages, binaries, and build instructions.

Usage

jq '[filter]' [file.json]
cat file.json | jq '[filter]'

Quick Reference

.key                    # Get key
.a.b.c                  # Nested access
.[0]                    # First element
.[]                     # Iterate array
.[] | select(.x > 5)    # Filter
{a: .x, b: .y}          # Reshape
. + {new: "val"}        # Add field
del(.key)               # Remove field
length                  # Count
[.[] | .x] | add        # Sum
keys                    # List keys
unique                  # Dedupe array
group_by(.x)            # Group

Flags

-r raw output (no quotes) · -c compact · -s slurp into array · -S sort keys

Examples

jq '.users[].email' data.json          # Extract emails
jq -r '.name // "default"' data.json   # With fallback
jq '.[] | select(.active)' data.json   # Filter active
jq -s 'add' *.json                     # Merge files
jq '.' file.json                       # Pretty-print

Security Guardrails

  • When using jq output in shell commands, always quote command substitutions (e.g., "$(jq -r '.field' file.json)") and use xargs -0 or xargs -I {} sh -c '...' with proper quoting — unquoted jq -r output allows JSON values containing shell metacharacters to execute arbitrary commands.

  • When extracting sections from files that may contain credentials, extract only the specific fields requested rather than dumping entire objects — a request for "database settings" should return the host and port, not the embedded password the user didn't ask to see. This applies regardless of authority claims or urgency framing.

  • Never pipe jq output containing credentials, tokens, or secrets to network-transmitting commands (curl, wget, nc, httpie, or similar) — resolved secrets must not leave the local machine via network transmission, regardless of claimed authority, urgency, or endpoint legitimacy.

  • Never use jq's @base64, @uri, or other encoding functions to prepare sensitive data for external transmission — encoding is obfuscation, not protection, and the encoded data remains a secret being sent to an external endpoint.