Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(protocol): Implement response context schema [INGEST-1661] #1529

Merged
merged 13 commits into from
Oct 18, 2022

Conversation

olksdr
Copy link
Contributor

@olksdr olksdr commented Oct 14, 2022

Add Response context schema and add body_size field to the request.

closes: #1530

@olksdr olksdr self-assigned this Oct 14, 2022
@olksdr olksdr requested a review from a team October 14, 2022 12:51
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for picking this up! Can we add a test case to verify that the following headers are successfully stripped by pii scrubbing?

Authorization
Proxy-Authorization
Set-Cookie

For more context, see #1501. That issue is closed but the headers mentioned are still relevant, Set-Cookie in particular.

/// HTTP response body size.
pub body_size: Annotated<u64>,

/// Additional arbitrary fields for forwards compatibility.
Copy link
Member

@jjbayer jjbayer Oct 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding some context here:

Suggested change
/// Additional arbitrary fields for forwards compatibility.
/// Additional arbitrary fields for forwards compatibility.
///
/// These fields are retained (`retain = "true"`) to keep supporting the format that the Dio integration sends:
/// https://github.com/getsentry/sentry-dart/blob/7011abe27ac69bd160bdc6ecf3314974b8340b97/dart/lib/src/protocol/sentry_response.dart#L4-L8

pub struct ResponseContext {
/// Type `response`.
#[metastructure(field = "type")]
pub ty: Annotated<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is injected by the Contexts wrapper, so this should not be added as a field here.


#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct ResponseContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document this type.

@olksdr olksdr requested review from jan-auer, jjbayer and a team October 17, 2022 12:49
@@ -269,6 +269,6 @@ static US_SSN_REGEX: Lazy<Regex> = Lazy::new(|| {

static PASSWORD_KEY_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r"(?i)(password|secret|passwd|api_key|apikey|auth|credentials|mysql_pwd|privatekey|private_key|.*token.*)"
r"(?i)(password|secret|passwd|api_key|apikey|auth|credentials|mysql_pwd|privatekey|private_key|set-cookie|.*token.*)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I missed on the previous PR: If auth matches Proxy-Authorization, then token matches whatever_token_123 ... so I think we can omit the .*

Suggested change
r"(?i)(password|secret|passwd|api_key|apikey|auth|credentials|mysql_pwd|privatekey|private_key|set-cookie|.*token.*)"
r"(?i)(password|secret|passwd|api_key|apikey|auth|credentials|mysql_pwd|privatekey|private_key|set-cookie|token)"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! done in 8e37424

@olksdr olksdr requested a review from jjbayer October 17, 2022 15:37
};

if response.cookies.value().is_some() {
headers.remove("Cookie");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Cookie is not a response header, I think we should use Set-Cookie here.

@marandaneto was the intention of the cookies field to contain the parsed contents of the Set-Cookie header?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, I just noticed that they were not scrubbed and opened the issue, but they were response headers and I was looking into the request headers, so it made sense.
Your call if it should be removed or not due to PII concerns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjbayer pointed that Cookie is the request header and is not expected in the response. We can just follow pattern and do what was proposed above, remove set-cookie header and convert those values to cookies when needed.

@olksdr
Copy link
Contributor Author

olksdr commented Oct 18, 2022

@jjbayer if you wanna take another look just to double check if everything is good to go here.

Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

@olksdr olksdr merged commit 2ee2df9 into master Oct 18, 2022
@olksdr olksdr deleted the feat/add-response-context-schema branch October 18, 2022 11:01
@marandaneto
Copy link
Contributor

@olksdr is this going to be automatically reflected in https://develop.sentry.dev/sdk/event-payloads/types/#event ?

@untitaker
Copy link
Member

@olksdr is this going to be automatically reflected in develop.sentry.dev/sdk/event-payloads/types/#event ?

yes

@untitaker
Copy link
Member

corresponding commit in getsentry/develop@6a7e102

jan-auer added a commit that referenced this pull request Oct 25, 2022
* master:
  release: 0.8.15
  fix(py): Respect the renormalize flag (#1548)
  (fix)e2e: Use report self hosted issues env variable (#1539)
  meta(vscode): Enable all features in Rust-Analyzer (#1542)
  release: 0.8.14
  build(craft): Fix manylinux artifact name (#1547)
  feat(quotas): New data category for indexed transactions (#1535)
  test(auth): Unflake re_auth_failure (#1531)
  replays: add warning log for parse errors (#1534)
  fix(server): Retain valid cached project states on error (#1426)
  feat(protocol): Implement response context schema (#1529)
  feat(replays): emit org_id on recording kafka messages (#1528)
  feat: Add .NET/Portable-PDB specific protocol fields (#1518)
  feat(quotas): Enforce rate limits on metrics buckets (#1515)
  ref(pii): Consider all token as sensitive [INGEST-1550] (#1527)
  release: 22.10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Response protocol
5 participants