diff options
author | r <r@freesoftwareextremist.com> | 2021-01-17 05:44:07 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2021-01-17 05:44:07 +0000 |
commit | f4620a8c69a71a4e99ed4e51346ec630f7c3aee2 (patch) | |
tree | 9066b66db1f573d3016c1d960cf686690c78736b /service | |
parent | e8bfd3093b0bf16c2ce56b3905ea640aa26d0127 (diff) | |
download | bloat-f4620a8c69a71a4e99ed4e51346ec630f7c3aee2.tar.gz bloat-f4620a8c69a71a4e99ed4e51346ec630f7c3aee2.zip |
Make redirection work without Referer header
Diffstat (limited to 'service')
-rw-r--r-- | service/service.go | 11 | ||||
-rw-r--r-- | service/transport.go | 48 |
2 files changed, 33 insertions, 26 deletions
diff --git a/service/service.go b/service/service.go index 088bcf4..01306d0 100644 --- a/service/service.go +++ b/service/service.go @@ -58,9 +58,11 @@ func NewService(clientName string, func getRendererContext(c *client) *renderer.Context { var settings model.Settings var session model.Session + var referrer string if c != nil { settings = c.Session.Settings session = c.Session + referrer = c.url() } else { settings = *model.NewSettings() } @@ -73,6 +75,7 @@ func getRendererContext(c *client) *renderer.Context { CSRFToken: session.CSRFToken, UserID: session.UserID, AntiDopamineMode: settings.AntiDopamineMode, + Referrer: referrer, } } @@ -545,7 +548,7 @@ func (s *service) UserSearchPage(c *client, if len(results.Statuses) == 20 { offset += 20 - nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, + nextLink = fmt.Sprintf("/usersearch/%s?q=%s&offset=%d", id, url.QueryEscape(q), offset) } @@ -608,7 +611,7 @@ func (s *service) SearchPage(c *client, if (qType == "accounts" && len(results.Accounts) == 20) || (qType == "statuses" && len(results.Statuses) == 20) { offset += 20 - nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d", + nextLink = fmt.Sprintf("/search?q=%s&type=%s&offset=%d", url.QueryEscape(q), qType, offset) } @@ -721,7 +724,7 @@ func (s *service) NewSession(instance string) (rurl string, sid string, err erro return } -func (s *service) Signin(c *client, code string) (token string, +func (s *service) Signin(c *client, code string) (token string, userID string, err error) { if len(code) < 1 { @@ -747,7 +750,7 @@ func (s *service) Signout(c *client) (err error) { return } -func (s *service) Post(c *client, content string, replyToID string, +func (s *service) Post(c *client, content string, replyToID string, format string, visibility string, isNSFW bool, files []*multipart.FileHeader) (id string, err error) { diff --git a/service/transport.go b/service/transport.go index 7ba52a4..882a351 100644 --- a/service/transport.go +++ b/service/transport.go @@ -46,6 +46,10 @@ type client struct { Session model.Session } +func (c *client) url() string { + return c.Req.URL.RequestURI() +} + func setSessionCookie(w http.ResponseWriter, sid string, exp time.Duration) { http.SetCookie(w, &http.Cookie{ Name: "session_id", @@ -301,7 +305,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { return err } - location := c.Req.Header.Get("Referer") + location := c.Req.FormValue("referrer") if len(replyToID) > 0 { location = "/thread/" + replyToID + "#status-" + id } @@ -319,7 +323,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -333,7 +337,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -347,7 +351,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -361,7 +365,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -373,7 +377,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+statusID) + redirect(c, c.Req.FormValue("referrer")+"#status-"+statusID) return nil }, CSRF, HTML) @@ -389,7 +393,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -399,7 +403,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -409,7 +413,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -419,7 +423,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -429,7 +433,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -439,7 +443,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -449,7 +453,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -459,7 +463,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -469,7 +473,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -479,7 +483,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -522,7 +526,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -532,7 +536,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -542,7 +546,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -553,7 +557,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if err != nil { return err } - redirect(c, c.Req.Header.Get("Referer")) + redirect(c, c.Req.FormValue("referrer")) return nil }, CSRF, HTML) @@ -567,7 +571,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) @@ -581,7 +585,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler { if len(rid) > 0 { id = rid } - redirect(c, c.Req.Header.Get("Referer")+"#status-"+id) + redirect(c, c.Req.FormValue("referrer")+"#status-"+id) return nil }, CSRF, HTML) |