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

matched class wasn't transformered and the issue appears just twice, and i didn't reproducing the issue #1600

Open
fuckeversec opened this issue Feb 23, 2024 · 10 comments
Assignees
Labels
Milestone

Comments

@fuckeversec
Copy link

fuckeversec commented Feb 23, 2024

jdk version is jdk-1.8.0_60s, and bytebuddy version is 1.10.22

the transformer code as belong:

@Override
public Builder<?> transform(Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader,
        JavaModule module) {

    if (isInterface().matches(typeDescription) || isEnum().matches(typeDescription)) {
        return builder;
    }

    List<InDefinedShape> needDesensitizeFields = typeDescription.getDeclaredFields()
        .filter(fieldDescriptionJunction);

    if (CollectionUtils.isEmpty(needDesensitizeFields)) {
        return builder;
    }

    log.info("class {} rebased", typeDescription.getTypeName());
    DESENSITIZATION_CLASSES.add(typeDescription.getTypeName());

    return builder.method(named("toString"))
        .intercept(MethodDelegation.to(LogAdvice.class))
        .field(isAnnotatedWith(Desensitization.class).and(
            ElementMatchers.not(ElementMatchers.isAnnotatedWith(JsonSerialize.class))))
        .annotateField(jacksonSerializeAnno);
}

there are two class A and B, they are all matched for this transformer, but the problem is just class B was transformered and class A was skipped, i use same jdk and same application jar, restart application 30000 times to reproducing the issue, but the problem was't occur.
I use net.bytebuddy.agent.ByteBuddyAgent.install method to instrumentation at runtime, doesn't use jvm agent method.

@raphw
Copy link
Owner

raphw commented Feb 23, 2024

Are you retransforming? If so, a class might be loaded when matching it. What does the log say? Does the missing class show up at all?

@fuckeversec
Copy link
Author

fuckeversec commented Feb 24, 2024

I didn't retransforming the class.

the matcher code is belong, use nameStartsWith to filter class.

agentBuilder.type(nameStartsWith("com.pay"))
                .transform(new JacksonFieldDesensitizingTransformer())

SendCashReq class has a field recvBankCardNum annotate with Desensitization:

@Desensitization("BANKCARD_MASK")
private String recvBankCardNum;

the issue case log is:
INFO: 2024-02-01 17:33:47.267 [main] JacksonFieldDesensitizingTransformer - [logid:] [clientip:] [localip:] class com.pay.epic.api.model.vo.ActivityBankCardInfoVo rebased

the correct case log is:
INFO: 2024-02-01 22:24:10.984 [main] JacksonFieldDesensitizingTransformer - [logid:] [clientip:] [localip:] class com.pay.epic.service.client.req.SendCashReq rebased
INFO: 2024-02-01 22:24:11.473 [main] JacksonFieldDesensitizingTransformer - [logid:] [clientip:] [localip:] class com.pay.epic.api.model.vo.ActivityBankCardInfoVo rebased

Like the above log shows, the application has two class matched the matcher's rule. SendCashReq class wasn't rebased, That case was occered twice.

@raphw
Copy link
Owner

raphw commented Feb 24, 2024

To me it seems as if SendCashReq is already loaded in that case. Are you logging ignored classes? Any class passed to Byte Buddy would get logged here.

@raphw raphw self-assigned this Feb 24, 2024
@raphw raphw added the question label Feb 24, 2024
@raphw raphw added this to the 1.14.12 milestone Feb 24, 2024
@fuckeversec
Copy link
Author

I think the class was already loaded too. I didn't log this message. I restart the application and use jvm option to logging loaded class. The SendCashReq class was at very later. What kind of case that make the SendCashReq was loadded at the beginning even before the main class. I install bytebuddy instrument at the main method first line.

@raphw
Copy link
Owner

raphw commented Feb 25, 2024

Do you reference losded classes somewhere? Byte Buddy would not load it itself. Are you running premain? In this case the app should not even come up before installing the sgent.

@fuckeversec
Copy link
Author

I use net.bytebuddy.agent.ByteBuddyAgent.install(), not running premain. But the install method is at first line in main method. I didn't reference SendCashReq on main classs.

@raphw
Copy link
Owner

raphw commented Feb 26, 2024

That's strange then. I'd activate logging of class loading on the JVM level and see if I can stitch it together based on that.

@fuckeversec
Copy link
Author

Hello, have you reproduced this issue? Have you identified the root cause of the problem?

@raphw
Copy link
Owner

raphw commented Mar 1, 2024

No, I have no opportunity to reproduce this problem. Did you try logging of class loading?

@fuckeversec
Copy link
Author

I logging of class loading when restart the application in test enviroment, but the error doesn't occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants