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 topic special tags #4031

Closed
wants to merge 1 commit into from
Closed

Conversation

lunny
Copy link
Member

@lunny lunny commented May 24, 2018

This will filter special tags on topics.

@lunny lunny added type/bug topic/security Something leaks user information or is otherwise vulnerable. Should be fixed! labels May 24, 2018
@lunny lunny added this to the 1.5.0 milestone May 24, 2018
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@11da1e6). Click here to learn what that means.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #4031   +/-   ##
=========================================
  Coverage          ?   19.97%           
=========================================
  Files             ?      153           
  Lines             ?    30484           
  Branches          ?        0           
=========================================
  Hits              ?     6090           
  Misses            ?    23480           
  Partials          ?      914
Impacted Files Coverage Δ
models/topic.go 54.78% <57.14%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11da1e6...d87510a. Read the comment docs.

@bkcsoft bkcsoft added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 24, 2018
@jonasfranz
Copy link
Member

If I add the topic "><iframe><div class=" it will result in:
screenshot-2018-5-24 xss

If I try to remove the same topic which I added before your PR will result in not removing it.
In the console this error appears:
Error: Syntax error, unrecognized expression: [data-value=""><iframe><div class=""] jquery.min.js:2:12731

@axifive
Copy link
Member

axifive commented Jun 10, 2018

I think for topics we need to add restrictions on the used symbols like GitHub topics and StackOverflow tags.

Rules:

  1. All topics are in lowercase
  2. Can be used only [a-z0-9_+.#-] symbols
  3. Length limitation - {1, 35} chars
  4. Number of topics added to the repository - max 25 topics
    ... maybe something else

Copy link
Member

@techknowlogick techknowlogick left a comment

Choose a reason for hiding this comment

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

I'm approving this because it gets rid of the security issue. A different PR can be created later to limit what can be in a tag.

@bkcsoft bkcsoft added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 15, 2018
Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

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

Only a few nit-picks

@@ -113,7 +118,8 @@ func SaveTopics(repoID int64, topicNames ...string) error {

var addedTopicNames []string
for _, topicName := range topicNames {
if strings.TrimSpace(topicName) == "" {
topicName = validTopic(topicName)
if topicName == "" {
Copy link
Member

Choose a reason for hiding this comment

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

if topicName = validTopic(topicName); len(topicName) == 0 {

@@ -133,6 +139,11 @@ func SaveTopics(repoID int64, topicNames ...string) error {
for _, t := range topics {
var found bool
for _, topicName := range topicNames {
topicName = validTopic(topicName)
if topicName == "" {
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@@ -2301,12 +2301,23 @@ function initNavbarContentToggle() {
});
}

function pasteFilter(e) {
Copy link
Member

@bkcsoft bkcsoft Jun 15, 2018

Choose a reason for hiding this comment

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

What does this magical function do? Mind adding that to a comment above the function? :)

Copy link
Member

Choose a reason for hiding this comment

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

It replaces all tags (substrings on the form <...>) with a space, " " when a user pastes, but I agree there should be a comment.

@jonasfranz
Copy link
Member

jonasfranz commented Jun 15, 2018

@techknowlogick I cannot follow you because the security issue is not resolved as I stated in a previous comment. If you think that this will resolve the problem, let me know it!

Edit: It actually resolves the security problem but introduces a bug as I mentioned in the previous comment.

@techknowlogick
Copy link
Member

techknowlogick commented Jun 15, 2018

@JonasFranzDEV yes. I give LG-TM because bug happens when a user has the "'s in their tag (at least that's the only way I can trigger it in my build of this branch), which hopefully is an uncommon character for a tag. This is why I am ok with the PR as it resolves the security, and still improves upon existing behavior.

It is almost my lunch hour, and so I might be able to send a patch to Lunny. Sadly I wasn't able to accomplish this.

@techknowlogick
Copy link
Member

@JonasFranzDEV what if in the validTopic function, the list of conditions that @axifive made were added?

@axifive
Copy link
Member

axifive commented Jun 15, 2018

@techknowlogick, I'm working on the full solution with front/back validation. And I also found repo topics duplication bug. I'll try to finish this on the weekend.

axifive added a commit to axifive/gitea that referenced this pull request Jun 16, 2018
Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@lunny lunny removed this from the 1.5.0 milestone Jun 17, 2018
@lunny
Copy link
Member Author

lunny commented Jun 17, 2018

closed by #4258

@lunny lunny closed this Jun 17, 2018
@lunny lunny deleted the lunny/fix_topic branch June 17, 2018 01:49
lunny pushed a commit that referenced this pull request Jun 21, 2018
* Added topics validation, fixed repo topics duplication (#4031)

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Added tests

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Fixed fmt

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Added comments to exported functions

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Deleted RemoveDuplicateTopics function

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Fixed messages

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Added migration

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* fmt migration file

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* fixed lint

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Added Copyright

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Added query solution for duplicates

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Fixed migration query

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Changed RegExp. Fixed migration

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* fmt migration file

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Fixed test for changed regexp

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Removed validation log messages

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Renamed migration file

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>

* Renamed validate function

Signed-off-by: Alexey Terentyev <axifnx@gmail.com>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. topic/security Something leaks user information or is otherwise vulnerable. Should be fixed! type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants