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

validate this code, sql injection #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LeandroGazoli
Copy link

SELECT ,
(SELECT COUNT(
) FROM "model_name"
WHERE to_tsvector('english',
coalesce("name", '') || ' ' ||
'X'; DROP TABLE users;--') @@ to_tsquery('english', 'X')
) AS row_count
FROM "model_name"
WHERE to_tsvector('english',
coalesce("name", '') || ' ' ||
'X'; DROP TABLE users;--') @@ to_tsquery('english', 'X')
limit ${options.perPage}
offset ${options.skip};

to

SELECT ,
(SELECT COUNT(
) FROM "model_name"
WHERE to_tsvector('english',
coalesce(:name, '') || ' ' ||
:searchValue) @@ to_tsquery('english', :searchValue)
) AS row_count
FROM "model_name"
WHERE to_tsvector('english',
coalesce(:name, '') || ' ' ||
:searchValue) @@ to_tsquery('english', :searchValue)
limit :perPage
offset :skip;

@Vladyslav317
Copy link

Hi @LeandroGazoli ! I've just checked your code and noticed that you created the same variable data but it isn't used within if condition. Instead, an empty data is used outside of it. Perhaps you intended to assign to the data variable declared outside of the scope.
Additionally, there are some typescript issues in if condition such as Untyped function calls may not accept type arguments. .

Once these issues are fixed, the code now returns the number of matched data instead of data with fields, as it did before. Please take a look and test your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants