Skip to content

Feature : in memoryy configg #92

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

Merged
merged 1 commit into from
Jul 12, 2025

Conversation

codewithtamim
Copy link
Contributor

@codewithtamim codewithtamim commented Jul 11, 2025

So this pr solves or enhances the issue #91 where they are concerned about like their config being stolen. I felt the same cause some attackers most of the time tries to get my config from the files directory where we write the temp config which is vulnerable in my view. So its a really great approach to solve the problem by just using in memory config and simplifies how we start xray , cause personally I hate it to write a config.json every time , its super boring !!!

Whatever now lets see how the pr solves the problem

so lets talk about the core functions that I have added firstly .

StartXrayFromJSON(configJSON string) (*core.Instance, error) -> It creates a xray instance from the json config given to it. so in the main xray-core we have a function like this inside core package

func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
	config, err := LoadConfig(configFormat, bytes.NewReader(configBytes))
	if err != nil {
		return nil, err
	}
	instance, err := New(config)
	if err != nil {
		return nil, err
	}
	if err := instance.Start(); err != nil {
		return nil, err
	}
	return instance, nil
}

what it does it takes the format (our case json and the config content in bytes) so when we deal normally with config.json file written in some location it uses the same function to process and get the instance by using the content bytes.

so in our StartXrayFromJSON(configJSON string) (*core.Instance, error) function we are writing a wrapper to that function simply thats it , no config.json file path related stuff required.


we get the json -> get bytes and then send to the StartInstance()

then here comes the main function that the issue mentioned needed to included
so its the function
 RunXrayFromJSON(datDir string, configJSON string) (err error) 


it takes the datdir path and the configJson file content 

then inits the env and simply starts the instance without involving any file writing so it works in memory.


these all are changes in xray.go

and in xray_wrapper.go I added wrapperss around these and some useful stuff like 

RunXrayFromJSONRequest -> struct for the request with json 


NewXrayRunFromJSONRequest(datDir, configJSON string) (string, error) -> for creating a request from json

and the actual RunXrayFromJSON(base64Text string) string which handles the connection.


so thats how I implemented or fixed the issue/feature/

feel free to do any counter questions, thanks ::::))))

So this pr solves or enhances the issue XTLS#91 where they are concerned about like their config being stolen. I felt the same cause some attackers most of the time tries to get my config from the files directory where we write the temp config which is vulnerable in my view. So its a really great approach to solve the problem by just using in memory config and simplifies how we start xray , cause personally I hate it to write a config.json every time , its super boring !!!

Whatever now lets see how the pr solves the problem

so lets talk about the core functions that I have added firstly .

StartXrayFromJSON(configJSON string) (*core.Instance, error) -> It creates a xray instance from the json config given to it. so in the main xray-core we have a function like this inside core package

```
func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
	config, err := LoadConfig(configFormat, bytes.NewReader(configBytes))
	if err != nil {
		return nil, err
	}
	instance, err := New(config)
	if err != nil {
		return nil, err
	}
	if err := instance.Start(); err != nil {
		return nil, err
	}
	return instance, nil
}```

what it does it takes the format (our case json and the config content in bytes) so when we deal normally with config.json file written in some location it uses the same function to process and get the instance by using the content bytes.

so in our StartXrayFromJSON(configJSON string) (*core.Instance, error)  function we are writing a wrapper to that function simply thats it , no config.json file path related stuff required.


we get the json -> get bytes  and then send to the StartInstance()

then here comes the main function that the issue mentioned needed to included
so its the function
 RunXrayFromJSON(datDir string, configJSON string) (err error) 


it takes the datdir path and the configJson file content

then inits the env and simply starts the instance without involving any file writing so it works in memory.


these all are changes in xray.go

and in xray_wrapper.go I added wrapperss around these and some useful stuff like 

RunXrayFromJSONRequest -> struct for the request with json


NewXrayRunFromJSONRequest(datDir, configJSON string) (string, error) -> for creating a request from json

and the actual RunXrayFromJSON(base64Text string) string which handles the connection.


so thats how I implemented or fixed the issue/feature/

feel free to do any counter questions, thanks ::::))))
@yiguodev yiguodev merged commit d3408e3 into XTLS:main Jul 12, 2025
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.

2 participants