Fix the User-Agent header name sent by mp_ua_header() - #936
Open
Jonas Lejon (jonaslejon) wants to merge 1 commit into
Open
Fix the User-Agent header name sent by mp_ua_header()#936Jonas Lejon (jonaslejon) wants to merge 1 commit into
Jonas Lejon (jonaslejon) wants to merge 1 commit into
Conversation
`mp_ua_header()` returned the key `UserAgent`, which is not the HTTP `User-Agent` header, so the MSTICPy identifier was sent under a header name nothing reads while httpx filled in the real `User-Agent` with its own default. Outbound requests were seen by services as `python-httpx/<version>`. `azure_monitor_driver` read `mp_ua_header()["UserAgent"]` to obtain the string for `UserAgentPolicy`. It now uses the exported `MSTICPY_USER_AGENT` constant, which is what it wants and is independent of the header name. Providers that declare their own `User-Agent` are unaffected: the guard in `http_provider.py` still leaves them alone, and now works as written.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mp_ua_header()returns the keyUserAgent, which is not the HTTPUser-Agentheader. The result is that the MSTICPy identifier is sent under a header name
nothing reads, and httpx fills in the real
User-Agentwith its own default, sorequests are seen by upstream services as
python-httpx/<version>.Reproducing
Pointing any
HttpTIProviderat a local HTTP server and dumping the receivedheaders shows both, with only the wrong one carrying our identifier:
Where it came from
The header was set correctly until #454. Before that change,
http_provider.pyread:and it became:
The guard still tests
User-Agent, but the key written is nowUserAgent, sothe guard never observes its own write. This means the intent of #319, to
identify MSTICPy in outbound HTTP requests, has not taken effect since then.
The change
Two lines:
common/utility/package.pyreturns{"User-Agent": ...}.data/drivers/azure_monitor_driver.pyusedmp_ua_header()["UserAgent"]toget the string for
UserAgentPolicy. It now uses the already-exportedMSTICPY_USER_AGENTconstant, which is what it actually wants and isindependent of the header name.
mp_ua_header()has 25 call sites across 14 modules, all of which pass it tohttpx as
headers=, so they are all corrected by (1).Providers that already declare their own
User-Agent(crowdsec,virustotal,prismacloud_driver) are unaffected: the guard inhttp_provider.pycontinues to leave them alone, and that guard now works aswritten.
Verification
tests/context/test_tiproviders.pyandtests/data/drivers/test_azure_monitor_driver.pypass. Changing only (1)fails
test_ti_config_and_loadwithKeyError: 'UserAgent', which is whatidentified the
azure_monitor_driverusage.User-Agent: MSTICPy...and noUserAgentheader.Note
This changes what every MSTICPy deployment sends on outbound requests, from
python-httpx/<version>to the MSTICPy identifier. That is the intendedbehaviour, but it is a visible change to upstream services rather than a no-op,
so it may be worth a release-note line.