bashにxargsコマンドを無視して記録させる方法は?

bashにxargsコマンドを無視して記録させる方法は?

私のコードは次のとおりです

echo "$result" | xargs -P50 -I@ bash -c '{ printf "@ $(curl --write-out "%{http_code}" -L -s --output /dev/null @)\n"; }'

これにはresult次のようなリストが含まれています。

https://example.com/somepath
https://example.com/somepath&quot
https://example.com/anotherpath?par1&par4=gg

期待される出力[URLステータスコード]

https://example.com/somepath 200
https://example.com/somepath&quot 200
https://example.com/anotherpath?par1&par4=gg 200

問題は、このコードスニペットを実行すると bash: quot: No such file or directoryandsignで区切られたエラーが発生&し、それを解決できないことです。

@一重引用符/二重引用符で囲みようとしましたが、何の効果もありませんでした。

ベストアンサー1

コマンド文字列に含まれる代替機能のためコマンド注入の脆弱性。これはタスクで見られるものです。curlの内容は、result使用された文字列引数だけでなく、コードで解析されます。

これを防ぐには、次のことを使用できます(主な問題にのみ焦点を当て、他の改善も可能です)。

printf '%s\n' "$result" | xargs -P50 -I@ bash -c 'printf "%s %s\n" "$1" \
  "$(curl --write-out "%{http_code}" -L -s --output /dev/null "$1")"' mybash @

おすすめ記事