
私のコードは次のとおりです
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"
https://example.com/anotherpath?par1&par4=gg
期待される出力[URLステータスコード]
https://example.com/somepath 200
https://example.com/somepath" 200
https://example.com/anotherpath?par1&par4=gg 200
問題は、このコードスニペットを実行すると
bash: quot: No such file or directory
andsignで区切られたエラーが発生&
し、それを解決できないことです。
@
一重引用符/二重引用符で囲みようとしましたが、何の効果もありませんでした。
答え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 @