Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SNYK-JS-CLASSVALIDATOR-1730566 #1668

Closed
avmaslov opened this issue Jun 4, 2022 · 2 comments
Closed

fix: SNYK-JS-CLASSVALIDATOR-1730566 #1668

avmaslov opened this issue Jun 4, 2022 · 2 comments
Labels
status: duplicate Issue is being tracked already in another issue. type: fix Issues describing a broken feature.

Comments

@avmaslov
Copy link

avmaslov commented Jun 4, 2022

Description

Affected versions of this package are vulnerable to Improper Input Validation via bypassing the input validation in validate(), which can lead to cross-site scripting (XSS) or SQL injection. NOTE: There is an optional forbidUnknownValues parameter that can be used to reduce the risk of this bypass.

For details see: https://security.snyk.io/vuln/SNYK-JS-CLASSVALIDATOR-1730566

Minimal code-snippet showcasing the problem

import { validate, validateOrReject, Contains, IsInt, Length, IsEmail, IsFQDN, IsDate, Min, Max } from "class-validator"; 
import { plainToClass } from "class-transformer";

class Post {
  @Length(10, 20) 
  title: string; 
  
  @IsInt() 
  @Min(0) 
  @Max(10) 
  rating: number; 
  
  @IsEmail() 
  email: string; 
  
  @IsFQDN() 
  site: string; 
  
  @IsDate() 
  createDate: Date;
}

let userJson = JSON.parse('{"title":1233, "proto":{}}'); // a malformed input 
let users = plainToClass(Post, userJson);

validate(users).then(errors => { // errors is an array of validation errors 
  if (errors.length > 0) { 
    console.log("validation failed. errors: ", errors); 
  } else { 
    console.log("validation succeed"); 
  } 
});

Expected behavior

How to prevent
This section describes the top best practices designed to specifically protect your code:
Sanitize data input in an HTTP request before reflecting it back, ensuring all data is validated, filtered or escaped before echoing anything back to the user, such as the values of query parameters during searches.
Convert special characters such as ?, &, /, <, > and spaces to their respective HTML or URL encoded equivalents.
Give users the option to disable client-side scripts.
Redirect invalid requests.
Detect simultaneous logins, including those from two separate IP addresses, and invalidate those sessions.
Use and enforce a Content Security Policy (source: Wikipedia) to disable any features that might be manipulated for an XSS attack.
Read the documentation for any of the libraries referenced in your code to understand which elements allow for embedded HTML.

Actual behavior

A cross-site scripting attack occurs when the attacker tricks a legitimate web-based application or site to accept a request as originating from a trusted source.

This is done by escaping the context of the web application; the web application then delivers that data to its users along with other trusted dynamic content, without validating it. The browser unknowingly executes malicious script on the client side (through client-side languages; usually JavaScript or HTML) in order to perform actions that are otherwise typically blocked by the browser’s Same Origin Policy.

@avmaslov avmaslov added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Jun 4, 2022
@braaar
Copy link
Member

braaar commented Nov 16, 2022

Closing this. Let's track this in #1422

@braaar braaar closed this as completed Nov 16, 2022
@braaar braaar added status: duplicate Issue is being tracked already in another issue. and removed status: needs triage Issues which needs to be reproduced to be verified report. labels Nov 16, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: duplicate Issue is being tracked already in another issue. type: fix Issues describing a broken feature.
Development

No branches or pull requests

2 participants