From 4e0375c76fcc301d523242bffc6ac5c015b7e4e0 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Sat, 10 Apr 2021 12:19:58 +0900 Subject: Don't include username in Referer --- url.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'url.c') diff --git a/url.c b/url.c index f099a0e..25bfb1b 100644 --- a/url.c +++ b/url.c @@ -1276,7 +1276,7 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current) } static Str -_parsedURL2Str(ParsedURL *pu, int pass) +_parsedURL2Str(ParsedURL *pu, int pass, int user, int label) { Str tmp; static char *scheme_str[] = { @@ -1293,13 +1293,13 @@ _parsedURL2Str(ParsedURL *pu, int pass) else if (pu->scheme == SCM_UNKNOWN) { return Strnew_charp(pu->file); } - if (pu->host == NULL && pu->file == NULL && pu->label != NULL) { + if (pu->host == NULL && pu->file == NULL && label && pu->label != NULL) { /* local label */ return Sprintf("#%s", pu->label); } if (pu->scheme == SCM_LOCAL && !strcmp(pu->file, "-")) { tmp = Strnew_charp("-"); - if (pu->label) { + if (label && pu->label) { Strcat_char(tmp, '#'); Strcat_charp(tmp, pu->label); } @@ -1327,7 +1327,7 @@ _parsedURL2Str(ParsedURL *pu, int pass) { Strcat_charp(tmp, "//"); } - if (pu->user) { + if (user && pu->user) { Strcat_charp(tmp, pu->user); if (pass && pu->pass) { Strcat_char(tmp, ':'); @@ -1361,7 +1361,7 @@ _parsedURL2Str(ParsedURL *pu, int pass) Strcat_char(tmp, '?'); Strcat_charp(tmp, pu->query); } - if (pu->label) { + if (label && pu->label) { Strcat_char(tmp, '#'); Strcat_charp(tmp, pu->label); } @@ -1371,7 +1371,13 @@ _parsedURL2Str(ParsedURL *pu, int pass) Str parsedURL2Str(ParsedURL *pu) { - return _parsedURL2Str(pu, FALSE); + return _parsedURL2Str(pu, FALSE, TRUE, TRUE); +} + +Str +parsedURL2RefererStr(ParsedURL *pu) +{ + return _parsedURL2Str(pu, FALSE, FALSE, FALSE); } int @@ -1459,20 +1465,13 @@ otherinfo(ParsedURL *target, ParsedURL *current, char *referer) current->scheme != SCM_LOCAL_CGI && current->scheme != SCM_DATA && (current->scheme != SCM_FTP || (current->user == NULL && current->pass == NULL))) { - char *p = current->label; Strcat_charp(s, "Referer: "); - current->label = NULL; - Strcat(s, parsedURL2Str(current)); - current->label = p; + Strcat(s, parsedURL2RefererStr(current)); Strcat_charp(s, "\r\n"); } else if (referer != NULL && referer != NO_REFERER) { - char *p = strchr(referer, '#'); Strcat_charp(s, "Referer: "); - if (p) - Strcat_charp_n(s, referer, p - referer); - else - Strcat_charp(s, referer); + Strcat_charp(s, referer); Strcat_charp(s, "\r\n"); } } @@ -1513,12 +1512,8 @@ HTTPrequestURI(ParsedURL *pu, HRequest *hr) Strcat_charp(tmp, pu->query); } } - else { - char *save_label = pu->label; - pu->label = NULL; - Strcat(tmp, _parsedURL2Str(pu, TRUE)); - pu->label = save_label; - } + else + Strcat(tmp, _parsedURL2Str(pu, TRUE, TRUE, FALSE)); return tmp; } -- cgit v1.2.3