Skip to content

Commit e3f5995

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

17 files changed

+52
-29
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, 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 == MaskSensitiveInfo::on ? " while masking" : ""));
679678
/* pack all entries one by one */
680679
while ((e = getEntry(&pos))) {
681-
if (!mask_sensitive_info) {
680+
if (masking == MaskSensitiveInfo::off) {
682681
e->packInto(p);
683682
continue;
684683
}

src/HttpHeader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
#include "anyp/ProtocolVersion.h"
1313
#include "base/LookupTable.h"
14+
#include "base/MaskSensitiveInfo.h"
1415
#include "http/RegisteredHeaders.h"
1516
/* because we pass a spec by value */
1617
#include "HttpHeaderMask.h"
1718
#include "mem/PoolingAllocator.h"
1819
#include "sbuf/forward.h"
20+
#include "security/forward.h"
1921
#include "SquidString.h"
2022

2123
#include <vector>
@@ -96,7 +98,9 @@ class HttpHeader
9698
/// \returns 0 when needs more data
9799
/// \returns -1 on error
98100
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;
101+
/// Serialize HTTP Fields using HTTP/1.1 syntax in RFC 9112 section 5.
102+
/// Optionally redact credentials in HTTP Authentication headers.
103+
void packInto(Packable *, MaskSensitiveInfo) const;
100104
HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const;
101105
HttpHeaderEntry *findEntry(Http::HdrType id) const;
102106
/// 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, 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, MaskSensitiveInfo::off);
338338
e->flush();
339339
}
340340

341341
/* packs request-line and headers, appends <crlf> terminator */
342342
void
343-
HttpRequest::pack(Packable * const p, const bool maskSensitiveInfo) const
343+
HttpRequest::pack(Packable * const p, MaskSensitiveInfo mask) const
344344
{
345345
assert(p);
346346
/* pack request-line */
347347
packFirstLineInto(p, false /* origin-form */);
348348
/* headers */
349-
header.packInto(p, maskSensitiveInfo);
349+
header.packInto(p, mask);
350350
/* indicate the end of the header section */
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, 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 maskSensitiveInfo = 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 * const, MaskSensitiveInfo) const;
208210

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

src/base/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ libbase_la_SOURCES = \
4848
JobWait.h \
4949
Lock.h \
5050
LookupTable.h \
51+
MaskSensitiveInfo.h \
5152
OnOff.h \
5253
Packable.h \
5354
PackableStream.h \

src/base/MaskSensitiveInfo.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3+
*
4+
* Squid software is distributed under GPLv2+ license and includes
5+
* contributions from numerous individuals and organizations.
6+
* Please see the COPYING and CONTRIBUTORS files for details.
7+
*/
8+
9+
#ifndef SQUID_SRC_BASE_MASKSENSITIVEINFO_H
10+
#define SQUID_SRC_BASE_MASKSENSITIVEINFO_H
11+
12+
#include "base/OnOff.h"
13+
14+
/// Flags for explicit decisions on handling of sensitive information.
15+
using MaskSensitiveInfo = OnOff;
16+
17+
#endif /* SQUID_SRC_BASE_MASKSENSITIVEINFO_H */

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, 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, 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, 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, MaskSensitiveInfo::off);
728728
hdr.clean();
729729

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

src/client_side_reply.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ clientReplyContext::traceReply()
10041004
http->storeEntry()->buffer();
10051005
MemBuf content;
10061006
content.init();
1007-
http->request->pack(&content, true /* hide authorization data */);
1007+
http->request->pack(&content, MaskSensitiveInfo::on);
10081008
const HttpReplyPointer rep(new HttpReply);
10091009
rep->setHeaders(Http::scOkay, nullptr, "message/http", content.contentSize(), 0, squid_curtime);
10101010
rep->body.set(SBuf(content.buf, content.size));

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, MaskSensitiveInfo::off);
156156
hdr_out.clean();
157157
mb.append("\r\n", 2);
158158

0 commit comments

Comments
 (0)