Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
126 views
in Technique[技术] by (71.8m points)

node.js - How to prevent javascript files from showing in view source?

I have a javascript file where my database function to fetch records is stored. This code below fetches the records from a specific Odoo model. Example code: RFQListApi.js:

const Odoo = require('odoo-await');


const rootUrl ='exampleURL'
const odoo = new Odoo({
    baseUrl: rootUrl,
    port: 24,
    db: 'test',
    username: "test123",
    password: "test123"
});


// Exporting to vue file

export default {
        async getList (){
            await odoo.connect();
            // Read data
            const records = await odoo.searchRead(`ship.order`, {}, ['name', 'subject']);
            return records
        }
}

Now I am calling this function by exporting this function to a VueJS file. Something like this:

<template>
  <div>
    <CRow>
      <CCol sm="12">
        <CTableWrapper
          :items="results"
          hover
          striped
          border
          small
          fixed
          caption="Request for Quotations"
        />
      </CCol>
    </CRow>

    
  </div>
</template>

<script>
import regeneratorRuntime from "regenerator-runtime";
import CTableWrapper from './RFQsTable.vue'
import RFQsList from './api/RFQsListApi';    // for API calling

export default {
  name: 'RFQsList',
  components: { CTableWrapper },
  data(){
    return{ 
      results: [],
      values:[]
    }
  },
  created(){
    this.getConnected();
  },
  methods: {
   async getConnected(){
      RFQsList.getList()
      .then((results) =>{
        this.$set(this,"results",results) // storing in event data()
    })
    .catch(e =>console.log(e, "Error from catch"))
    },
  }
}
</script>

As you can see all the details from the RFQsListApi.js file, such as username and password are visible and anyone can access these files by viewing the source. What can I do to protect or hide these username and other sensitive details from others.

question from:https://stackoverflow.com/questions/65931466/how-to-prevent-javascript-files-from-showing-in-view-source

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As you can see all the details from the RFQsListApi.js file, such as username and password are visible and anyone can access these files by viewing the source.

Among other methods, such as just watching the files go over the network, or using a debugging console, or a browser extension, etc. etc.

What can I do to protect or hide these username and other sensitive details from others.

You can't. If you send someone some information, they have that information. If someone needs to use that information (such as a password) then they necessarily need to access that information, and there's nothing you can do to prevent it from being out there.

You need to do something differently, where the username/password isn't sent to everyone. Usually, each user's session will be given a temporary token representing that user, and the server will do actions on a database on their behalf, authenticating/verifying as you go.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...