Skip to main content
Fix spelling of JSON.
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

Sanitize JsonJSON for sending with Curl

I have to send a POST request to some service with jsonJSON payload, and it includes some user input. That input variable needs to be JsonJSON-encoded to prevent injection attacks.

Code example that sends requests and parses response jsonJSON to RESP variable:

RESP=`curl --connect-timeout "10" -s -H "Content-Type: application/json" \
        -X POST -d '{ "Attribute": '"'$USERINPUT'" }',\
        $ENDPOINT | $JQ -r '.key'`

howHow to sanitize, or jsonJSON encode $USERINPUT, $USERINPUT before creating jsonJSON payload?

Sanitize Json for sending with Curl

I have to send a POST request to some service with json payload, and it includes some user input. That input variable needs to be Json-encoded to prevent injection attacks.

Code example that sends requests and parses response json to RESP variable:

RESP=`curl --connect-timeout "10" -s -H "Content-Type: application/json" \
        -X POST -d '{ "Attribute": '"'$USERINPUT'" }',\
        $ENDPOINT | $JQ -r '.key'`

how to sanitize, or json encode $USERINPUT before creating json payload?

Sanitize JSON for sending with Curl

I have to send a POST request to some service with JSON payload, and it includes some user input. That input variable needs to be JSON-encoded to prevent injection attacks.

Code example that sends requests and parses response JSON to RESP variable:

RESP=`curl --connect-timeout "10" -s -H "Content-Type: application/json" \
        -X POST -d '{ "Attribute": '"'$USERINPUT'" }',\
        $ENDPOINT | $JQ -r '.key'`

How to sanitize, or JSON encode, $USERINPUT before creating JSON payload?

Source Link
Hrvoje Hudo
  • 151
  • 1
  • 1
  • 3

Sanitize Json for sending with Curl

I have to send a POST request to some service with json payload, and it includes some user input. That input variable needs to be Json-encoded to prevent injection attacks.

Code example that sends requests and parses response json to RESP variable:

RESP=`curl --connect-timeout "10" -s -H "Content-Type: application/json" \
        -X POST -d '{ "Attribute": '"'$USERINPUT'" }',\
        $ENDPOINT | $JQ -r '.key'`

how to sanitize, or json encode $USERINPUT before creating json payload?