Skip to content

Commit e393f1c

Browse files
committed
Add flag MaskSensitiveInfo
to allow for explicit caller controlled redaction of Authentication credentials in generated outputs.
1 parent 49e5e74 commit e393f1c

File tree

15 files changed

+36
-28
lines changed

15 files changed

+36
-28
lines changed

src/HttpHeader.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,16 +669,15 @@ HttpHeader::parse(const char *header_start, size_t hdrLen, Http::ContentLengthIn
669669

670670
/* packs all the entries using supplied packer */
671671
void
672-
HttpHeader::packInto(Packable * p, bool mask_sensitive_info) const
672+
HttpHeader::packInto(Packable * p, Security::MaskSensitiveInfo masking) const
673673
{
674674
HttpHeaderPos pos = HttpHeaderInitPos;
675675
const HttpHeaderEntry *e;
676676
assert(p);
677-
debugs(55, 7, this << " into " << p <<
678-
(mask_sensitive_info ? " while masking" : ""));
677+
debugs(55, 7, this << " into " << p << (masking == Security::MaskSensitiveInfo::on ? " while masking" : ""));
679678
/* pack all entries one by one */
680679
while ((e = getEntry(&pos))) {
681-
if (!mask_sensitive_info) {
680+
if (masking == Security::MaskSensitiveInfo::off) {
682681
e->packInto(p);
683682
continue;
684683
}

src/HttpHeader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "HttpHeaderMask.h"
1717
#include "mem/PoolingAllocator.h"
1818
#include "sbuf/forward.h"
19+
#include "security/forward.h"
1920
#include "SquidString.h"
2021

2122
#include <vector>
@@ -96,7 +97,9 @@ class HttpHeader
9697
/// \returns 0 when needs more data
9798
/// \returns -1 on error
9899
int parse(const char *buf, size_t buf_len, bool atEnd, size_t &hdr_sz, Http::ContentLengthInterpreter &interpreter);
99-
void packInto(Packable * p, bool mask_sensitive_info=false) const;
100+
/// Serialize HTTP Fields using HTTP/1.1 syntax in RFC 9112 section 5.
101+
/// Optionally redact credentials in HTTP Authentication headers.
102+
void packInto(Packable *, Security::MaskSensitiveInfo) const;
100103
HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const;
101104
HttpHeaderEntry *findEntry(Http::HdrType id) const;
102105
/// deletes all fields with a given name, if any.

src/HttpReply.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void
8787
HttpReply::packHeadersUsingFastPacker(Packable &p) const
8888
{
8989
sline.packInto(&p);
90-
header.packInto(&p);
90+
header.packInto(&p, Security::MaskSensitiveInfo::off);
9191
p.append("\r\n", 2);
9292
}
9393

src/HttpRequest.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,19 +334,19 @@ HttpRequest::swapOut(StoreEntry * e)
334334
{
335335
assert(e);
336336
e->buffer();
337-
pack(e);
337+
pack(e, Security::MaskSensitiveInfo::off);
338338
e->flush();
339339
}
340340

341341
/* packs request-line and headers, appends <crlf> terminator */
342342
void
343-
HttpRequest::pack(Packable * p, bool mask_sensitive_data) const
343+
HttpRequest::pack(Packable * p, Security::MaskSensitiveInfo mask) const
344344
{
345345
assert(p);
346346
/* pack request-line */
347347
packFirstLineInto(p, false /* origin-form */);
348348
/* headers */
349-
header.packInto(p, mask_sensitive_data);
349+
header.packInto(p, mask);
350350
/* frame terminator */
351351
p->append("\r\n", 2);
352352
}
@@ -358,7 +358,7 @@ void
358358
httpRequestPack(void *obj, Packable *p)
359359
{
360360
HttpRequest *request = static_cast<HttpRequest*>(obj);
361-
request->pack(p);
361+
request->pack(p, Security::MaskSensitiveInfo::off);
362362
}
363363

364364
/* returns the length of request line + headers + crlf */

src/HttpRequest.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ class HttpRequest: public Http::Message
204204

205205
void swapOut(StoreEntry * e);
206206

207-
void pack(Packable * p, bool mask_sensitive_info = false) const;
207+
/// Serialize HTTP Request using HTTP/1.1 origin-form syntax in RFC 9112 section 3.
208+
/// \copydoc HttpHeader::packInto()
209+
void pack(Packable *, Security::MaskSensitiveInfo) const;
208210

209211
static void httpRequestPack(void *obj, Packable *p);
210212

src/client_side.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,22 @@ prepareLogWithRequestDetails(HttpRequest *request, const AccessLogEntryPointer &
327327
if (Config.onoff.log_mime_hdrs) {
328328
MemBuf mb;
329329
mb.init();
330-
request->header.packInto(&mb);
330+
request->header.packInto(&mb, Security::MaskSensitiveInfo::off);
331331
//This is the request after adaptation or redirection
332332
aLogEntry->headers.adapted_request = xstrdup(mb.buf);
333333

334334
// the virgin request is saved to aLogEntry->request
335335
if (aLogEntry->request) {
336336
mb.reset();
337-
aLogEntry->request->header.packInto(&mb);
337+
aLogEntry->request->header.packInto(&mb, Security::MaskSensitiveInfo::off);
338338
aLogEntry->headers.request = xstrdup(mb.buf);
339339
}
340340

341341
#if USE_ADAPTATION
342342
const Adaptation::History::Pointer ah = request->adaptLogHistory();
343343
if (ah != nullptr) {
344344
mb.reset();
345-
ah->lastMeta.packInto(&mb);
345+
ah->lastMeta.packInto(&mb, Security::MaskSensitiveInfo::off);
346346
aLogEntry->adapt.last_meta = xstrdup(mb.buf);
347347
}
348348
#endif
@@ -724,7 +724,7 @@ clientPackRangeHdr(const HttpReplyPointer &rep, const HttpHdrRangeSpec * spec, S
724724

725725
httpHeaderAddContRange(&hdr, *spec, rep->content_length);
726726

727-
hdr.packInto(mb);
727+
hdr.packInto(mb, Security::MaskSensitiveInfo::off);
728728
hdr.clean();
729729

730730
/* append <crlf> (we packed a header, not a reply) */

src/clients/HttpTunneler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Http::Tunneler::writeRequest()
152152
&hdr_out,
153153
connection->getPeer(),
154154
flags);
155-
hdr_out.packInto(&mb);
155+
hdr_out.packInto(&mb, Security::MaskSensitiveInfo::off);
156156
hdr_out.clean();
157157
mb.append("\r\n", 2);
158158

src/errorpage.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ ErrorState::Dump(MemBuf * mb)
886886
body << "HTTP Request:\r\n";
887887
MemBuf r;
888888
r.init();
889-
request->pack(&r, true /* hide authorization data */);
889+
request->pack(&r, Security::MaskSensitiveInfo::on);
890890
body << r.content();
891891
}
892892

@@ -1149,7 +1149,7 @@ ErrorState::compileLegacyCode(Build &build)
11491149
break;
11501150
}
11511151
else if (request)
1152-
request->pack(&mb, true /* hide authorization data */);
1152+
request->pack(&mb, Security::MaskSensitiveInfo::on);
11531153
else
11541154
p = "[no request]";
11551155
break;

src/htcp.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, Ip::Ad
833833
hdr.putInt(Http::HdrType::AGE, 0);
834834
MemBuf mb;
835835
mb.init();
836-
hdr.packInto(&mb);
836+
hdr.packInto(&mb, Security::MaskSensitiveInfo::off);
837837
stuff.D.resp_hdrs = xstrdup(mb.buf);
838838
stuff.D.respHdrsSz = mb.contentSize();
839839
debugs(31, 3, "htcpTstReply: resp_hdrs = {" << stuff.D.resp_hdrs << "}");
@@ -846,7 +846,7 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, Ip::Ad
846846
if (e && e->lastModified() > -1)
847847
hdr.putTime(Http::HdrType::LAST_MODIFIED, e->lastModified());
848848

849-
hdr.packInto(&mb);
849+
hdr.packInto(&mb, Security::MaskSensitiveInfo::off);
850850

851851
stuff.D.entity_hdrs = xstrdup(mb.buf);
852852
stuff.D.entityHdrsSz = mb.contentSize();
@@ -872,7 +872,7 @@ htcpTstReply(htcpDataHeader * dhdr, StoreEntry * e, htcpSpecifier * spec, Ip::Ad
872872
}
873873
#endif /* USE_ICMP */
874874

875-
hdr.packInto(&mb);
875+
hdr.packInto(&mb, Security::MaskSensitiveInfo::off);
876876
stuff.D.cache_hdrs = xstrdup(mb.buf);
877877
stuff.D.cacheHdrsSz = mb.contentSize();
878878
debugs(31, 3, "htcpTstReply: cache_hdrs = {" << stuff.D.cache_hdrs << "}");
@@ -1534,7 +1534,7 @@ htcpQuery(StoreEntry * e, HttpRequest * req, CachePeer * p)
15341534
HttpStateData::httpBuildRequestHeader(req, e, nullptr, &hdr, p, flags);
15351535
MemBuf mb;
15361536
mb.init();
1537-
hdr.packInto(&mb);
1537+
hdr.packInto(&mb, Security::MaskSensitiveInfo::off);
15381538
hdr.clean();
15391539
stuff.S.req_hdrs = mb.buf;
15401540
pktlen = htcpBuildPacket(pkt, sizeof(pkt), &stuff);
@@ -1588,7 +1588,7 @@ htcpClear(StoreEntry * e, HttpRequest * req, const HttpRequestMethod &, CachePee
15881588
if (reason != HTCP_CLR_INVALIDATION) {
15891589
HttpStateData::httpBuildRequestHeader(req, e, nullptr, &hdr, p, flags);
15901590
mb.init();
1591-
hdr.packInto(&mb);
1591+
hdr.packInto(&mb, Security::MaskSensitiveInfo::off);
15921592
hdr.clean();
15931593
stuff.S.req_hdrs = mb.buf;
15941594
} else {

src/http.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ HttpStateData::buildRequestPrefix(MemBuf * mb)
23992399
upgradeHeaderOut = new String(hdr.getList(Http::HdrType::UPGRADE));
24002400
}
24012401

2402-
hdr.packInto(mb);
2402+
hdr.packInto(mb, Security::MaskSensitiveInfo::off);
24032403
hdr.clean();
24042404
}
24052405
/* append header terminator */

0 commit comments

Comments
 (0)