You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/modules
oliverpool b6e81357bd
Add Webhook authorization header (#20926)
_This is a different approach to #20267, I took the liberty of adapting
some parts, see below_

## Context

In some cases, a weebhook endpoint requires some kind of authentication.
The usual way is by sending a static `Authorization` header, with a
given token. For instance:

- Matrix expects a `Bearer <token>` (already implemented, by storing the
header cleartext in the metadata - which is buggy on retry #19872)
- TeamCity #18667
- Gitea instances #20267
- SourceHut https://man.sr.ht/graphql.md#authentication-strategies (this
is my actual personal need :)

## Proposed solution

Add a dedicated encrypt column to the webhook table (instead of storing
it as meta as proposed in #20267), so that it gets available for all
present and future hook types (especially the custom ones #19307).

This would also solve the buggy matrix retry #19872.

As a first step, I would recommend focusing on the backend logic and
improve the frontend at a later stage. For now the UI is a simple
`Authorization` field (which could be later customized with `Bearer` and
`Basic` switches):


![2022-08-23-142911](https://user-images.githubusercontent.com/3864879/186162483-5b721504-eef5-4932-812e-eb96a68494cc.png)

The header name is hard-coded, since I couldn't fine any usecase
justifying otherwise.

## Questions

- What do you think of this approach? @justusbunsi @Gusted @silverwind 
- ~~How are the migrations generated? Do I have to manually create a new
file, or is there a command for that?~~
- ~~I started adding it to the API: should I complete it or should I
drop it? (I don't know how much the API is actually used)~~

## Done as well:

- add a migration for the existing matrix webhooks and remove the
`Authorization` logic there


_Closes #19872_

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Gusted <williamzijl7@hotmail.com>
Co-authored-by: delvh <dev.lh@web.de>
2 years ago
..
activitypub Refactor AssertExistsAndLoadBean to use generics (#20797) 3 years ago
analyze Simplify `IsVendor` (#19626) 3 years ago
auth Remove legacy `+build:` constraint (#19582) 3 years ago
avatar Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
base Add generic set type (#21408) 2 years ago
cache Update go-chi/cache to utilize Ping() (#19719) 3 years ago
charset Move go-licenses to generate and separate generate into a frontend and backend component (#21061) 3 years ago
container Add generic set type (#21408) 2 years ago
context Fix package access for admins and inactive users (#21580) 2 years ago
convert Add Webhook authorization header (#20926) 2 years ago
csv Go 1.19 format (#20758) 3 years ago
doctor Merge db.Iterate and IterateObjects (#21641) 2 years ago
emoji Go 1.19 format (#20758) 3 years ago
eventsource Move some files into models' sub packages (#20262) 3 years ago
generate Use base32 for 2FA scratch token (#18384) 3 years ago
git Keep languages defined in .gitattributes (#21403) 2 years ago
gitgraph Refactor git command arguments and make all arguments to be safe to be used (#21535) 2 years ago
graceful Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
hcaptcha hCaptcha Support (#12594) 5 years ago
highlight Upgrade chroma to v2.3.0 (#21259) 3 years ago
hostmatcher Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
httpcache Add Cache-Control header to html and api responses, add no-transform (#20432) 3 years ago
httplib refactor httplib (#18338) 3 years ago
indexer Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
issue/template Deal with markdown template without metadata (#21639) 2 years ago
json Refactor legacy `unknwon/com` package, improve golangci lint (#19284) 3 years ago
lfs Removed some vestigial code related to Range bounds checks (#20312) 3 years ago
log Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
markup Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
mcaptcha Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
metrics Move some files into models' sub packages (#20262) 3 years ago
migration Add more checks in migration code (#21011) 3 years ago
mirror Implement sync push mirror on commit (#19411) 3 years ago
nosql fix broken insecureskipverify handling in rediss connection uris (#20967) 3 years ago
notification feat: notify doers of a merge when automerging (#21553) 2 years ago
options Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
packages Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
paginator Remove unnecessary misspell ignore pattern (#21475) 2 years ago
password Fixed assert statements. (#16089) 4 years ago
pprof Go 1.19 format (#20758) 3 years ago
private Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
process Add more linters to improve code readability (#19989) 3 years ago
proxy Return nil proxy function if proxy not enabled (#16742) 4 years ago
proxyprotocol Support Proxy protocol (#12527) 3 years ago
public Add generic set type (#21408) 2 years ago
queue Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
recaptcha Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
references Remove unnecessary misspell ignore pattern (#21475) 2 years ago
regexplru Custom regexp external issues (#17624) 3 years ago
repository Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551) 2 years ago
secret Use `CryptoRandomBytes` instead of `CryptoRandomString` (#18439) 3 years ago
session format with gofumpt (#18184) 3 years ago
setting Allow disable sitemap (#21617) 2 years ago
sitemap Add sitemap support (#18407) 3 years ago
ssh Support Proxy protocol (#12527) 3 years ago
storage Save files in local storage as umask (#21198) 3 years ago
structs Add Webhook authorization header (#20926) 2 years ago
svg Remove legacy `+build:` constraint (#19582) 3 years ago
sync Add generic set type (#21408) 2 years ago
system Sync git hooks when config file path changed (#21619) 2 years ago
templates feat: notify doers of a merge when automerging (#21553) 2 years ago
test Refactor AssertExistsAndLoadBean to use generics (#20797) 3 years ago
timeutil Fix `Timestamp.IsZero` (#21593) 2 years ago
translation Make every not exist error unwrappable to a fs.ErrNotExist (#20891) 2 years ago
typesniffer Rework raw file http header logic (#20484) 3 years ago
updatechecker Add system setting table with cache and also add cache supports for user setting (#18058) 2 years ago
upload Simplify parameter types (#18006) 3 years ago
uri Prevent NPE if gitea uploader fails to open url (#18080) 3 years ago
user Add gitea-vet (#10948) 5 years ago
util Make every not exist error unwrappable to a fs.ErrNotExist (#20891) 2 years ago
validation Add more checks in migration code (#21011) 3 years ago
watcher Share HTML template renderers and create a watcher framework (#20218) 3 years ago
web refactor webhook *NewPost (#20729) 3 years ago