Я использую flask -marshmallow для проверки ввода пользователя.
from marshmallow import Schema, fields, validate
class UserSchema(Schema):
username = fields.String(required=True,
validate=[validate.Length(min=1, error="Field should not be empty.")])
pincode = fields.Integer(required=True, validate=validate.Range(
min=0, error="pincode is invalid, it should be a positive integer."))
В части контроллера приложения:
class UserDetails(Resource):
user_schema_obj = UserSchema()
def post(self):
if not request.is_json:
return make_response(jsonify(error_dict(
current_request_id(), "Unsupported media type, Requests must be JSON",
415)), status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)
if not request.json:
return make_response(jsonify(error_dict(
current_request_id(), "Required parameter not found",
400)), status.HTTP_400_BAD_REQUEST)
request_jsn = UserDetails.user_schema_obj.load(request.get_json())
username = request_jsn['username']
pincode = request_jsn['pincode']
Так я передаю вводимые пользователем данные в схему зефира. когда я делаю сканирование приложения, оно говорит gets user input from element **get_json**. This element’s value flows through the code without being properly sanitized or validated and is eventually stored in the server-side Session object, in post
. Это представляет собой нарушение границы доверия. Не знаете, как решить эту проблему? Пожалуйста, помогите!