Pass Gitea API token to requests#9

Merged
momar merged 4 commits from :main into main 2021-12-01 21:46:29 +01:00
Owner

In case you want to allow non-public repos, this should do the job. But I'm fine if we decide everything needs to be 100% public - this just adds the ability e.g. to use an API token from a random user who only has access to limited repos.


This allows to display repos that aren't fully public. Some users seem
to be very interested in not having their pages viewable, and it might
make even sense to avoid e.g. search engines to read them.
If set to some random user string, this could allow to set the
visibility at least to limited (so only logged users see the repo), and
should allow to view private repos in the future with another API token.

In case you want to allow non-public repos, this should do the job. But I'm fine if we decide everything needs to be 100% public - this just adds the ability e.g. to use an API token from a random user who only has access to limited repos. --- This allows to display repos that aren't fully public. Some users seem to be very interested in not having their pages viewable, and it might make even sense to avoid e.g. search engines to read them. If set to some random user string, this could allow to set the visibility at least to limited (so only logged users see the repo), and should allow to view private repos in the future with another API token.
main.go Outdated
@ -39,6 +39,8 @@ var MainDomainSuffix = []byte("." + envOr("PAGES_DOMAIN", "codeberg.page"))
// GiteaRoot specifies the root URL of the Gitea instance, without a trailing slash.
var GiteaRoot = []byte(envOr("GITEA_ROOT", "https://codeberg.org"))
var GiteaApiToken = []byte(envOr("GITEA_API_TOKEN", ""))
Contributor

why use []byte if it will get converted to string later?

why use []byte if it will get converted to string later?
Owner

Probably because the other variables used it? Reason for that is that []byte is preferred by fasthttp, but in this case it's only ever used in a string, so having it as a string here as well makes sense.

Probably because the other variables used it? Reason for that is that `[]byte` is preferred by fasthttp, but in this case it's only ever used in a string, so having it as a string here as well makes sense.
momar marked this conversation as resolved
momar left a comment
Owner

Found a security issue (token gets exposed to the client), see code comments for details.

Found a security issue (token gets exposed to the client), see code comments for details.
handler.go Outdated
@ -153,3 +153,3 @@
s.Step("raw domain preparations, now trying with specified branch")
if tryBranch(targetRepo, pathElements[2][1:], pathElements[3:],
string(GiteaRoot)+"/"+targetOwner+"/"+targetRepo+"/src/branch/%b/%p",
string(GiteaRoot)+"/"+targetOwner+"/"+targetRepo+"/src/branch/%b/%p"+"?access_token="+string(GiteaApiToken),
Owner

This is the "canonicalLink" argument that's exposed to the client as a Link header (to indicate the official URL in Gitea to e.g. search engines), the token must not be added here!

I'd prefer to only have it directly at fasthttp Requests, so the token really only goes to Gitea.

This is the "canonicalLink" argument that's exposed to the client as a `Link` header (to indicate the official URL in Gitea to e.g. search engines), the token must not be added here! I'd prefer to only have it directly at `fasthttp` Requests, so the token really only goes to Gitea.
Author
Owner

sorry, I missed this was the canonicalLink. I thought this would pass down to the default branch query, but missed this was another API call in getBranchTimestamp.

sorry, I missed this was the canonicalLink. I thought this would pass down to the default branch query, but missed this was another API call in getBranchTimestamp.
momar marked this conversation as resolved
handler.go Outdated
@ -165,3 +165,3 @@
s.Step("raw domain preparations, now trying with default branch")
tryBranch(targetRepo, "", pathElements[2:],
string(GiteaRoot)+"/"+targetOwner+"/"+targetRepo+"/src/branch/%b/%p",
string(GiteaRoot)+"/"+targetOwner+"/"+targetRepo+"/src/branch/%b/%p"+"?access_token="+string(GiteaApiToken),
Owner
Same as https://codeberg.org/Codeberg/pages-server/pulls/9/files#issuecomment-282995
momar marked this conversation as resolved
Author
Owner

Wasn't able to properly test this, your ACME server is unavailable, but it feels alright.

Wasn't able to properly test this, your ACME server is unavailable, but it *feels* alright.
momar approved these changes 2021-12-01 21:46:13 +01:00
momar merged commit 5b6e3748b4 into main 2021-12-01 21:46:29 +01:00
Sign in to join this conversation.
No description provided.