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 X-Robots-Tag header valid values check #40715

Merged
merged 9 commits into from
Apr 26, 2023
Merged

Conversation

rizlas
Copy link
Contributor

@rizlas rizlas commented Mar 30, 2023

Description

Currently the only accepted value for the robots tag is none but:

Related Issue

Motivation and Context

Allow all the possible values of x-robots-tag header and handle duplicate headers if OC is behind a proxy

How Has This Been Tested?

  • test environment: fully working environment with OC 10.12 (docker)
  • test case 1: x-robots-tag header values: 'none, noindex, nofollow, nosnippet, noarchive'
  • test case 2: x-robots-tag header values: 'none, nosnippet, noarchive'
  • test case 3: x-robots-tag header values: 'none'
  • test case 4: x-robots-tag header values: 'nofollow, nosnippet' [security warning raised]
  • test case 5: x-robots-tag header values: 'nosnippet, noarchive' [security warning raised]
  • test case 6: x-robots-tag header values: 'noindex, nofollow'
  • test case 7: x-robots-tag header values: '' [security warning raised]

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:
  • Changelog item, see TEMPLATE

@update-docs
Copy link

update-docs bot commented Mar 30, 2023

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@CLAassistant
Copy link

CLAassistant commented Mar 30, 2023

CLA assistant check
All committers have signed the CLA.

@rizlas rizlas marked this pull request as draft March 31, 2023 07:15
@rizlas rizlas marked this pull request as ready for review March 31, 2023 08:24
Co-authored-by: ho4ho <42564859+ho4ho@users.noreply.github.com>
@phil-davis
Copy link
Contributor

Reviewers - after review is all done, merge this and include in 10.12.1 or wait?

@phil-davis phil-davis requested a review from IljaN April 2, 2023 09:21
@jvillafanez
Copy link
Member

You might also want to create a function in order to move all the checks there. The idea would be to add support for arrays, so you could use 'X-Robots-Tag': 'none' or 'X-Robots-Tag': ['none', 'noindex', 'nofollow'],.

Note that I'm just commenting about the code itself. I don't know if the code is right or wrong.

@jnweiger
Copy link
Contributor

jnweiger commented Apr 3, 2023

Reviewers - after review is all done, merge this and include in 10.12.1 or wait?

I'd say wait.
a) because 10.12.1 is about to be shipped. and
b) this one touches security - hardening related topics. We need deeper understanding why we recommend 'none'.
Reference:
https://doc.owncloud.com/server/next/admin_manual/configuration/server/harden_server.html#use-of-security-related-headers-on-the-web-server

My understanding here:
Both alternatives: a) none + optional extra values and also b) noindex + nofollow + optional extra values effectively mean 'none'. So it seems to be safe to me. We need to take care, that in the case b) we need to assert that both are present, and not just one of them. (or one of them combined with none).

@rizlas
Copy link
Contributor Author

rizlas commented Apr 15, 2023

@jvillafanez array is used only during validation. It is not a valid type input. Imho a separate function is not needed.

@jnweiger combinations of none, noindex, nofollow, nosnippet, noarchive are 32 (2^5) and they are:

''
none
noindex
nofollow
nosnippet
noarchive
none, noindex
none, nofollow
none, nosnippet
none, noarchive
noindex, nofollow
noindex, nosnippet
noindex, noarchive
nofollow, nosnippet
nofollow, noarchive
nosnippet, noarchive
none, noindex, nofollow
none, noindex, nosnippet
none, noindex, noarchive
none, nofollow, nosnippet
none, nofollow, noarchive
none, nosnippet, noarchive
noindex, nofollow, nosnippet
noindex, nofollow, noarchive
noindex, nosnippet, noarchive
nofollow, nosnippet, noarchive
none, noindex, nofollow, nosnippet
none, noindex, nofollow, noarchive
none, noindex, nosnippet, noarchive
none, nofollow, nosnippet, noarchive
noindex, nofollow, nosnippet, noarchive
none, noindex, nofollow, nosnippet, noarchive

With the current code these combinations are not valid:

''
noindex
nofollow
nosnippet
noarchive
noindex, nosnippet
noindex, noarchive
nofollow, nosnippet
nofollow, noarchive
nosnippet, noarchive
noindex, nosnippet, noarchive
nofollow, nosnippet, noarchive

On the contrary these are valid input:

none
none, noindex
none, nofollow
none, nosnippet
none, noarchive
noindex, nofollow
none, noindex, nofollow
none, noindex, nosnippet
none, noindex, noarchive
none, nofollow, nosnippet
none, nofollow, noarchive
none, nosnippet, noarchive
noindex, nofollow, nosnippet
noindex, nofollow, noarchive
none, noindex, nofollow, nosnippet
none, noindex, nofollow, noarchive
none, noindex, nosnippet, noarchive
none, nofollow, nosnippet, noarchive
noindex, nofollow, nosnippet, noarchive
none, noindex, nofollow, nosnippet, noarchive

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@jvillafanez jvillafanez left a comment

Choose a reason for hiding this comment

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

This should be fine assuming there won't be changes in the checks. I mean, the "X-Robots-Tag" header will be the only exception to the exact match of key - values we're checking.

@phil-davis
Copy link
Contributor

10.12.1 has been merged back to master, so we can merge new stuff like this.

@phil-davis phil-davis merged commit 7297fdd into owncloud:master Apr 26, 2023
@rizlas
Copy link
Contributor Author

rizlas commented Apr 26, 2023

Thank you

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.

X-Robots-Tag security check
5 participants