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

Try to make the SQL queries cleaner and more secure #2893

Merged
merged 2 commits into from
Mar 27, 2016
Merged

Try to make the SQL queries cleaner and more secure #2893

merged 2 commits into from
Mar 27, 2016

Conversation

tboerger
Copy link
Contributor

It's a start as a followup to #2892

if len(cond) > 0 {
sess.And(cond)
}
sess := x.Limit(20, (page-1)*20).Where("is_closed=?", isClosed).In("repo_id", rids)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More personal preference than anything else, but I like to have each sentence in each line:

sess := x.
    Limit(20, (page-1)*20).
    Where("is_closed = ?", isClosed).
    In("repo_id", rids)

Apart from that, 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @unknwon have not done that so far I won't change it like that :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify, what happens if rids is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify, what happens if rids is empty?

https://github.com/go-xorm/xorm/blob/master/statement.go#L743-L745
Need to check what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to verify, what happens if rids is empty?

Look above within the function, you have done already a check, e.g. if len(rids) == 0 {

@tboerger
Copy link
Contributor Author

@unknwon if you are fine with that you can already merge that. If I can improve also other parts I will create more followup pull requests.

@unknwon unknwon added the status: needs feedback Tell me more about it label Mar 27, 2016
if opts.UserID > 0 {
queryStr += " AND issue_user.uid=" + com.ToStr(opts.UserID)
sess.Where("issue_user.uid = ?", opts.UserID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be?:

sess = sess.Where("issue_user.uid = ?", opts.UserID)

At least is how it would work on Gorm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see on all the query updates above this seems to be not required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to change to sess.And.

@unknwon unknwon removed the status: needs feedback Tell me more about it label Mar 27, 2016
@unknwon
Copy link
Member

unknwon commented Mar 27, 2016

Thanks!

@unknwon unknwon merged commit 7f26ae0 into gogs:develop Mar 27, 2016
@tboerger tboerger deleted the feature/sql-security branch March 27, 2016 21:43
}

if opts.IsMention {
queryStr := "issue.id=issue_user.issue_id AND issue_user.is_mentioned=1"
sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id AND issue_user.is_mentioned = 1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why join here where it did not?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants