GHSA-gc7p-j5xm-xxh2

    Dashboard / Vulnerabilities / GHSA-gc7p-j5xm-xxh2

    GHSA-gc7p-j5xm-xxh2

    Published: 3 Nov 2023Last Modified: 8 Nov 2023

    Summary: Unauthorized Access to Private Fields in User Registration API

    Details: ### System Details | Name | Value | |----------|------------------------| | OS | Windows 11 | | Version | 4.11.1 (node v16.14.2) | | Database | mysql | ### Description I marked some fields as private fields in user content-type, and tried to register as a new user via api, at the same time I added content to fill the private fields and sent a post request, and as you can see from the images below, I can write to the private fields. ![register](https://user-images.githubusercontent.com/32245914/246987508-9337ffd5-c681-4f51-9a0b-2490b424ca1e.png) ![user](https://user-images.githubusercontent.com/32245914/246987564-9f440b3f-a7a3-4710-9b75-0854667fc35d.png) ![private_field](https://user-images.githubusercontent.com/32245914/246987590-9c0ecefd-fd64-4221-b642-e730ea55d440.png) ![table](https://user-images.githubusercontent.com/32245914/246987604-009e6808-5690-458e-aa87-57dda7d4589d.png) To prevent this, I went to the extension area and tried to extend the register method, for this I wanted to do it using the sanitizeInput function that I know in the source codes of the strap. But the sanitizeInput function did not filter out private fields. ```js const { auth } = ctx.state; const data = ctx.request.body; const userSchema = strapi.getModel("plugin::users-permissions.user"); sanitize.contentAPI.input(data, userSchema, { auth }); ``` here's the solution I've temporarily kept to myself, code snippet ```js const body = ctx.request.body; const { attributes } = strapi.getModel("plugin::users-permissions.user"); const sanitizedData = _.omitBy(body, (data, key) => { const attribute = attributes[key]; if (_.isNil(attribute)) { return false; } //? If you want, you can throw an error for fields that we did not expect. // if (_.isNil(attribute)) // throw new ApplicationError(`Unexpected value ${key}`); // if private value is true, we do not want to send it to the database. return attribute.private; }); return sanitizedData; ```

    Affected packages

    Package

    Name: @strapi/plugin-users-permissions

    Purl: pkg:npm/%40strapi/plugin-users-permissions

    Affected ranges

    Type: SEMVER

    Events:

    Introduced- 4.0.0
    Fixed -4.13.1

    Affected versions

    Common Vulnerability Scoring System

    Attack Vector
    Network
    Adjacent
    Local
    Physical
    Privileges Required
    None
    Low
    High
    User Interaction
    None
    Required
    Scope
    Unchanged
    Changed
    Confidentiality
    None
    Low
    High
    Integrity
    None
    Low
    High
    Availability
    None
    Low
    High
    GHSA-gc7p-j5xm-xxh2 | CVE-DB