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

secondary name exists in binary,can it be removed? #1051

Open
o2e opened this issue Feb 14, 2022 · 5 comments
Open

secondary name exists in binary,can it be removed? #1051

o2e opened this issue Feb 14, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@o2e
Copy link

o2e commented Feb 14, 2022

I used @NameInDb to rename the field names in the DB, but after testing in the security department I found that the member names of the entity still exist in the binary. I changed the name in the entity again and objectbox still works. After using NameInDb, is the actual member name of the entity still valuable? For me, it takes extra space and leaks my actual mapped names of entity members, I really like objectbox, I'm trying to modify the generation tool, but no progress. Is there an easy way to configure it? I don't seem to find it in the documentation (maybe I'm missing something )

objectbox ver:3.1.1
work on android project

@o2e o2e added the enhancement New feature or request label Feb 14, 2022
@greenrobot-team
Copy link
Member

greenrobot-team commented Feb 14, 2022

The @NameInDb annotation is kept in compiled code so the annotation processor can access it (if I remember correctly). Edit: never mind, it shouldn't be kept, odd.

Anyhow, maybe using the @Uid annotation is what you are looking for: https://docs.objectbox.io/advanced/data-model-updates Then code can refer to the UID instead of the name of a property.

@o2e
Copy link
Author

o2e commented Feb 14, 2022

I read this documentation on UIDs carefully and he does have the ability to change the field names at will. It fits the description of the documentation.

But my idea is to remove the "secondaryName" content written in the DB binary when it is first generated, I have a table as shown in the code below
image

Then is a simple view of the DB binary file
Screenshot_2022-02-14-15-53-01-601_com speedsoftw

As you can see, it contains the names of the members of my entity inside. Our security engineers believe that if @NameInDb is used there should not be an actual member name.

For this reason I modified the "buildEntityAccount" logic in "MyObjectBox" using a hook, so that "secondaryName("uin ")" into an empty string for testing, and it doesn't seem to affect the operation of objectbox.
47447B5E-9343-4EE1-84DF-10758C9ABAF1

I think removing "secondaryName" is harmless and beneficial, it reduces the binary footprint and improves the security of the program to some extent (security engineers say it prevents hackers from tracing sensitive logic through field names backwards, which makes the program less secure), I agree (of course I don't know if this will affect the intuitiveness of debug output).
Screenshot_2022-02-14-15-50-55-299_com speedsoftw

Now that I can make it execute with the logic I want through a hook inside the program, would you consider removing the "secondaryName" field that is written into the binary?

@greenrobot-team
Copy link
Member

The secondary name needs to be passed to the native component so it can properly create entity objects and set data to fields, e.g. for get or query. It's odd though that it is actually stored in the database.

Did you try this with a new (vs. existing) database?

@o2e
Copy link
Author

o2e commented Feb 15, 2022

I have tried two scenarios,

1、using the original logic to create a good database and insert a new row, then prevent the value of "secondaryName" to pass in and then insert and query, objectbox does not report errors, insert and query (including conditional query) everything is normal.

2、Use the logic after my hook ( prevent the value of "secondaryName" from being passed in ) and then create a database and insert new data and query, no error occurs. Then unhook, use the original logic to query and insert all normal. Because I renamed the database using @NameInDb.

MyObjectBox hard-coded the member name of the entity when it was generated, and usually the apk will be obfuscated after the Android development, the member name of the entity at this time already does not match the name generated by MyObjectBox, he relies on @NameInDb query, "secondaryName" has no real value

image
image

What I think is that when you have @NameInDb. should give up writing "secondaryName" to the binary data

This is just my personal opinion, but it doesn't stop me from loving objectbox

@greenrobot-team
Copy link
Member

Sorry, more details: it works in your case because ObjectBox can use the all argument constructor provided by the Kotlin data class to create the Account object. But with ObjectBox it's also possible to just provide a default or other constructor (also think of Java using getter/setter), then ObjectBox will access the fields/properties directly. In that case obfuscation will also break creating an object.

Example:

@Entity
data class DefaultConstructorExample(
    @Id var id: Long = 0,
    var name: String = "",
    @Transient var total: Int = 0
)

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

No branches or pull requests

2 participants